note 16298 deleted from function.preg-replace by jimw
| From: | jimw@php.net | Date: | Thu, 20 Dec 2001 23:29:21 +0000 |
| Subject: | note 16298 deleted from function.preg-replace by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23565@lists.php.net to get a copy of this message | ||
Took me forever to find this, so I thought I'd share - if you want to search a string for
occorences of another, excepting cases where the search string appears within an HTML tag, and you
surround the results with HTML, here's what you need:
$strIn = preg_replace("/(^| |\n|\r|\t|\]|>|\")(".$searchterm.")(([\.,]+[
$\n\r\t])|$|\"|<|\[| |\n|\r|\t)/si", '\\1<span
class="cssHighlight">\\2</span>\\3', $strIn);
This is in the code of the vBulletin software, available at vBulletin.com. It's used in the
search engine to highlight searched-for terms in results.