note 16298 added to function.preg-replace

From: Date: Wed, 24 Oct 2001 05:32:07 +0000
Subject: note 16298 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-19361@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. -- http://www.php.net/manual/en/function.preg-replace.php http://master.php.net/manage/user-notes.php?action=edit+16298 http://master.php.net/manage/user-notes.php?action=delete+16298 http://master.php.net/manage/user-notes.php?action=reject+16298

« previous php.notes (#19361) next »