note 67992 added to function.preg-replace

From: Date: Sun, 09 Jul 2006 02:21:00 +0000
Subject: note 67992 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-114604@lists.php.net to get a copy of this message
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; ?> ---- Server IP: 203.16.234.91 Probable Submitter: 60.228.191.194 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/note/edit/67992 Del: integrated -- http://master.php.net/note/delete/67992/integrated Del: useless -- http://master.php.net/note/delete/67992/useless Del: bad code -- http://master.php.net/note/delete/67992/bad+code Del: spam -- http://master.php.net/note/delete/67992/spam Del: non-english -- http://master.php.net/note/delete/67992/non-english Del: in docs -- http://master.php.net/note/delete/67992/in+docs Del: other reasons-- http://master.php.net/note/delete/67992 Reject -- http://master.php.net/note/reject/67992 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114604) next »