Re: Help on pregreplace

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

 



You should check out preg_quote() function which puts a backslash in front of characters (escapes them) that have a special meaning in regular expressions.

Regards,
Vladan Stefanovic


"Merlin Morgenstern" <merlin_x@xxxxxxxxxxx> wrote in message news:12.62.22194.004BA8A4@xxxxxxxxxxxxxxx
Hi there,

I am highlighting keywords with the help of pregreplace. This works great with one limitation. If the word that has to be replaced contains a slash, preg throws an error. So far I could not find a fix. Can someone help?

Here is the code:


   $pattern = "/\b($words)\b/is";
$replace = '<span style="background:#FF0000;color:#FCCCCC;">\\1</span>';
   return preg_replace($pattern,$replace,$str);

Thank you in advance,

Merlin


--
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