note 19520 added to function.preg-replace
| From: | volker at multiartstudio dot de | Date: | Fri, 01 Mar 2002 16:33:19 +0000 |
| Subject: | note 19520 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27234@lists.php.net to get a copy of this message | ||
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
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+19520
http://master.php.net/manage/user-notes.php?action=delete+19520
http://master.php.net/manage/user-notes.php?action=reject+19520