Re: Help on pregreplace
| From: | Vladan Stefanovic | Date: | Tue, 18 Aug 2009 14:19:53 +0000 |
| Subject: | Re: Help on pregreplace | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296928@lists.php.net to get a copy of this message | ||
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@fastmail.fm> wrote in message news:12.62.22194.004BA8A4@pb1.pair.com...
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