]> git.mjollnir.org Git - moodle.git/commitdiff
New highlight function for searches etc
authormartin <martin>
Tue, 11 Jun 2002 07:01:51 +0000 (07:01 +0000)
committermartin <martin>
Tue, 11 Jun 2002 07:01:51 +0000 (07:01 +0000)
lib/weblib.php

index 409ad29df71b5f4e46c7523e7d8e25d6f43a6a64..2efda8dd988d35976bb0229ab9f642f206daf50f 100644 (file)
@@ -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));
+}
+
 
 ?>