Re: Help on pregreplace
| From: | tedd | Date: | Wed, 19 Aug 2009 14:26:07 +0000 |
| Subject: | Re: Help on pregreplace | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296969@lists.php.net to get a copy of this message | ||
At 10:51 AM -0400 8/18/09, Al wrote:
Merlin Morgenstern wrote:In addition, you might consider moving your style attributes to a style sheet and then using a class name like so: $replace = '<span class="highlight">\\1</span>'; That way you can change highlighting as you want without altering your code. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.comHi 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, Merlinbest insurance http://us2.php.net/manual/en/function.preg-quote.php