[Phpwm] help with function

Phil Beynon phil at infolinkelectronics.co.uk
Fri Mar 23 02:14:53 GMT 2007


Hi all,

This little function is for highlighting a search term in some data, you
give it the string of data and what you want to search for and it highlights
it in red. I've swapped out the class that does this for a font tag for
clarity.

It works just about perfectly, and I've been using for some time.

Except last night I searched on '.' and discovered if that's done it
replaces every char in the data variable with the same number of .s - all
nicely highlighted, and I cannot for the life of me see why.


function highlight($data,$search){								//highlight the search results
$textarr = preg_split("/(<.*>|&.*;)/Us",$data,-1,PREG_SPLIT_DELIM_CAPTURE);
//make array
foreach($textarr as $key => $value){							//parse array
if(strpos($value,"<") === false AND
in_array($value,get_html_translation_table(HTML_ENTITIES)) === false)
{$textarr[$key] = eregi_replace($search,"<FONT style=\"BACKGROUND-COLOR:
#ff0000\">" . $search . "</FONT>",$value);}
}
return implode("",$textarr);} 								//return array as var



Phil




More information about the Phpwm mailing list