mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 16:13:28 +02:00
New highlight function for searches etc
This commit is contained in:
parent
0157e3bfba
commit
5af78ed2b2
1 changed files with 18 additions and 0 deletions
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue