note 63219 added to function.preg-replace

From: Date: Thu, 16 Mar 2006 10:46:46 +0000
Subject: note 63219 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-105913@lists.php.net to get a copy of this message
I said there was a better way. There is! The regexp is essentially the same but now I deal with problems that it couldn't handle, such as urls, which tended to screw things up, and the odd placement of a : or ; in the body text, by using functions. This makes it easier to expand to take account of all the things I know I've not taken account of. But here it is in its essential glory. Or mediocrity. Take your pick. <?php define('PARSER_ALLOWED_STYLES_', 'text-align,font-family,font-size,text-decoration'); function strip_styles($source=NULL) { $exceptions = str_replace(',', '|', @constant('PARSER_ALLOWED_STYLES_')); /* First we want to fix anything that might potentially break the styler stripper, sow e try and replace * in-text instances of : with its html entity replacement. */ function Replacer($text) { $check = array ( '@:@s', ); $replace = array( '&#58;', ); return preg_replace($check, $replace, $text[0]); } $source = preg_replace_callback('@>(.*)<@Us', 'Replacer', $source); $regexp = '@([^;"]+)?(?<!'. $exceptions. ')(?<!\>\w):(?!\/\/(.+?)\/|<|>)((.*?)[^;"]+)(;)?@is'; $source = preg_replace($regexp, '', $source); $source = preg_replace('@[a-z]*=""@is', '', $source); return $source; } ?> ---- Server IP: 85.116.0.130 Probable Submitter: 86.144.119.249 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/note/edit/63219 Del: integrated -- http://master.php.net/note/delete/63219/integrated Del: useless -- http://master.php.net/note/delete/63219/useless Del: bad code -- http://master.php.net/note/delete/63219/bad+code Del: spam -- http://master.php.net/note/delete/63219/spam Del: non-english -- http://master.php.net/note/delete/63219/non-english Del: in docs -- http://master.php.net/note/delete/63219/in+docs Del: other reasons-- http://master.php.net/note/delete/63219 Reject -- http://master.php.net/note/reject/63219 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105913) next »