note 67992 deleted from function.preg-replace by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 20:02:27 +0000 |
| Subject: | note 67992 deleted from function.preg-replace by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127700@lists.php.net to get a copy of this message | ||
Note Submitter: kurt at yachthub dot com
----
Fix up for most common bad punctuation round commas and fullstops, remove white space, make the
first letter of a sentence uppercase and replace dubious characters like &, ", ', etc.
with special html characters.
<?
$string=" harry's house.4. 2m long 3.5m wide.63\" but great . seating ,
for 7.pjljk.cost is $12, 00.00.Good buy .0.0. 1.1m\n";
echo "<pre>$string</pre><p>";
$pat[0] = '/\./';
$pat[1] = '/ \./';
$pat[2] = '/\,/';
$pat[3] = '/ \,/';
$pat[4] = '/\n /';
$pat[5] = '/ +/';
$repl[0] = '. ';
$repl[1] = '.';
$repl[2] = ', ';
$repl[3] = ', ';
$repl[4] = '\n';
$repl[5] = ' ';
$string=split("\. ",trim(ucfirst(stripslashes(htmlspecialchars(preg_replace($pat, $repl,
$string),ENT_QUOTES)))));
foreach ($string as $key=>$word) {
$string[$key] = ucfirst($word);
}
$string = implode ('. ', $string);
$i=0;
while($i < 10){
$pat[$i] = '/'.$i.'\. /';
$repl[$i] = ''.$i.'.';
$i++;
}
while($i < 36){
$b=$i+55;
$pat[$i] = '/\.'.chr($b).'/';
$repl[$i] = '. '.chr($b).'';
$i++;
}
while($i < 46){
$b=$i-36;
$pat[$i] = '/'.$b.'\, /';
$repl[$i] = ''.$b.',';
$i++;
}
$string = preg_replace($pat, $repl, $string);
echo $string;
?>