highlighting search results (revisited)

From: Date: Tue, 17 Apr 2001 11:35:32 +0000
Subject: highlighting search results (revisited)
Groups: php.general 
Request: Send a blank email to php-general+get-48934@lists.php.net to get a copy of this message
I am trying to write a little search script to search a mysql db. I would like to highlight the search words for the displayed results, like sourceforge etc... After a little help, I have got it to hightlight when searching for one word. The problem is if I do a search for more than one word it repeats the hightlighting. here's the code I got so far $bg = explode("%",$string); while($db->next_record()) { $title = $db->f("title"); $des = $db->f("description"); for($z=0; $z < count($bg); $z++) { if(next($bg) == false) { reset($bg); } $bgstring = current($bg); $title = preg_replace("/($bgstring+)/ie", "'<span class=highlight>\\1</span>'", $title); $des = preg_replace ("/($bgstring+)/ie", "'<span class=highlight>\\1</span>'", $des); } echo $title.NL; echo $des.NL.NL; } The problem is is I search for class or span it screws up the code as it replaces the span or class in the original tag. How could I stop this? I know this another rex ex thing and I'm gonna get the oreilly book when I'm next in the city but untill then it's driving me bonkers. TIA M@

« previous php.general (#48934) next »