Permalink
Browse files

New highlight function for searches etc

  • Loading branch information...
1 parent 0157e3b commit 5af78ed2b206e81c184aedf475bc362d0b4db424 martin committed Jun 11, 2002
Showing with 18 additions and 0 deletions.
  1. +18 −0 lib/weblib.php
View
@@ -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));
+}
+
?>

0 comments on commit 5af78ed

Please sign in to comment.