highlight keywords issue
| From: | Hatem Ben | Date: | Sun, 12 Jan 2003 09:23:47 +0000 |
| Subject: | highlight keywords issue | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-131322@lists.php.net to get a copy of this message | ||
Heya all,
I'm trying to highlight search keywords in a string, everything work expect
when this keyword is inside a tag like this :
keyword (php) :
<a href="?go=php">php</a>
<img src="php.gif" border=0 alt="php.net">
will be highlighted to :
<a href="?go=<b style="color: black; background-color:
#ffff66">php</b>"><b
style="color: black; background-color: #ffff66">php</b></a>
<img src="<b style="color: black; background-color:
#ffff66">php</b>.gif"
border=0 alt="<b style="color: black; background-color:
#ffff66">php</b>.net">
I have tryed to separate text from html, then highlight it then join
html/text again, but this will be very long and not really usefull !
I'm using preg_replace :
preg_replace('|\b('.quotemeta($keyword).')\b|iU', '<b style="color:
black;
background-color: #ffff66">\\1</b>', $content);
Any help to fix that ?
Thanks;
Hatem