RE: [PHP] highlighting search results (revisited)

From: Date: Wed, 18 Apr 2001 09:12:03 +0000
Subject: RE: [PHP] highlighting search results (revisited)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49163@lists.php.net to get a copy of this message
Hi James I'll paste the code I use.. $string = search string entered in the text box. ############################################################# // REPLACE SPACES FOR MULTIWORD SEARCH $string = str_replace(" ","%",$string); $db->query("SELECT title,description FROM files WHERE (title LIKE '%$string%') || (description LIKE '%$string%')"); // SPLIT THE SEARCH INTO PARTS FOR HIGHLIGHTING $bg = explode("%",$string); while($db->next_record()) { $title = $db->f("title"); $des = $db->f("description"); for($z=0; $z < count($bg); $z++) { // reset the array if it's at the end if(next($bg) == false) { reset($bg); } $bgstring = current($bg); $title = preg_replace("/($bgstring+)/ie", "'<span class=message>\\1</span>'", $title); $des = preg_replace ("/($bgstring+)/ie", "'<span class=message>\\1</span>'", $des); } echo $title.NL; echo $des.NL.NL; } ############################################################### The above code works as expected....except if I search for span and say class; now this will highlight span in the search string found from the database but on the second run ie. hightlighting class, it will re-highlight the <span> in the span tags from the original pass. Do you get what I mean?? preg_replace is used to keep the original case of the results as it's a case insensitive search I need to be able to replace only result that aren't enclosed in a class tag Cheers M@

« previous php.general (#49163) next »