Here's the situation. I've created a spiffy-looking MySQL database search engine. It's supposed to highlight each keyword like google does. I'm not looking to do different colors or anything; I just want each keyword to be highlighted. So far, I've gotten it to work. I can search for as many keywords as I like with the exception of a string that is any part of the HTML with which I use to highlight it.
This is my highlight function, along with its call for one of the columns.
Code: Select all
$Record->Name = SearchHighlight($KeywordArray,"$Record->Name");
function SearchHighlight($WordArray, $BigString, $AddBef = '<font class="SearchHighlight">', $AddAft = '</font>'){
if (is_array($WordArray)){
foreach($WordArray as $Word){
$BigString = eregi_replace($Word, $AddBef . "\\0" . $AddAft, $BigString);
}
}else{
$BigString = eregi_replace($WordArray, $AddBef . "\\0" . $AddAft, $BigString);
}
return $BigString;
}If I search for 'mike' it will work fine, but if I search for both 'mike' and 't' it will highlight 'mike', then highlight everything with 't'...which would be what I wanted, if it didn't highlight the 't' that's part of my HTML tag.
mike
http://www.99main.com/~arkaine/misc/contacts1.gif
mike t
http://www.99main.com/~arkaine/misc/contacts2.gif
I must have spent hours scouring the internet/forums to figure out a way to ignore html tags, juggle strings, or anything. Now I've finaly given into what I told myself I'd never do...I'm posting.
Please help me! I'm at such a loss!