note 19520 deleted from function.preg-replace by sniper
| From: | sniper@php.net | Date: | Sun, 07 Sep 2003 22:09:51 +0000 |
| Subject: | note 19520 deleted from function.preg-replace by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55719@lists.php.net to get a copy of this message | ||
Note Submitter: volker@multiartstudio.de
----
hi, here is a little hack i figured out to highlight some text matches a searchstring in html based
documents, without destroying html-tags....
(this was necessary to scan database-entry written in html by keywords, and display them in another
style....a mini google :))
here it is:
$C=preg_replace("/(\>(((?>[^><]+)|(?R))*)\<)/ie",
"preg_replace('/(?>$search+)/i','<span
class=\"searchnfound\">$search</span>',
'\\0')",
$C);
!!!put it all in one-line!!!!
where $C is the content you want to scan and highlight the string given by $search.
searchnfound is a simple style-class for displaying the keyword in another style.
but be careful, you must scan the string $search for special characters before ..
otherwise searching for e.g. '*' would give nasty results :)!
you can try it at : www.erdtrabant.de
bye, volker