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@


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to