Re: preg_replace (again)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux