From: martin Date: Tue, 11 Jun 2002 07:01:51 +0000 (+0000) Subject: New highlight function for searches etc X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5af78ed2b206e81c184aedf475bc362d0b4db424;p=moodle.git New highlight function for searches etc --- diff --git a/lib/weblib.php b/lib/weblib.php index 409ad29df7..2efda8dd98 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -304,5 +304,23 @@ function text_to_html($text, $smiley=true) { return "

".$text."

"; } +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] .= "".substr($haystack, $pos, strlen($needle)).""; + $pos += strlen($needle); + } + + return (join('', $parts)); +} + ?>