Re: preg_replace (again)

From: Date: Fri, 22 Sep 2006 23:22:19 +0000
Subject: Re: preg_replace (again)
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-242098@lists.php.net to get a copy of this message
On Wed, September 20, 2006 11:20 am, Pawel Miroslawski wrote: > Hi > it's example script: > > <?php > $string = "This is some _color:pink_ colored text _color_"; > > $patterns[0] = '/_color:(.*?)_/'; > $patterns[1] = '/_color_/'; > $replacements[0] = '<font color="$1">'; > $replacements[1] = '</font>'; > > echo preg_replace($patterns, $replacements, $string); > ?> > > It should be ok, but i don't test it. For the sanitization... .*? could be something more like: [#a-z0-9A-Z]+ The # assumes you want to allow #ff0000 style colors. Since this whitelists the specific characters you allow, it's probably better than the strip_tags thing. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#242098) next »