New highlight function for searches etc
This commit is contained in:
@@ -304,5 +304,23 @@ function text_to_html($text, $smiley=true) {
|
||||
return "<P>".$text."</P>";
|
||||
}
|
||||
|
||||
function highlight($needle, $haystack) {
|
||||
// This function will highlight instances of $needle in $haystack
|
||||
|
||||
$parts = explode(strtolower($needle), strtolower($haystack));
|
||||
|
||||
$pos = 0;
|
||||
|
||||
foreach ($parts as $key => $part) {
|
||||
$parts[$key] = substr($haystack, $pos, strlen($part));
|
||||
$pos += strlen($part);
|
||||
|
||||
$parts[$key] .= "<SPAN CLASS=highlight>".substr($haystack, $pos, strlen($needle))."</SPAN>";
|
||||
$pos += strlen($needle);
|
||||
}
|
||||
|
||||
return (join('', $parts));
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user