This script was sent to us as a
request when we wanted a script that highlighted text
we searched for. The demonstartion shows this but also
shows a drawback as it finds and highlights the phrase
in a completely different word.
Here is the script
<?php
function highlight_search($search_words, $message)
{
$bgcolor = "yellow";
foreach ($search_words as $search_word)
{
$message = eregi_replace("($search_word)", "<span
style=\"background-color: $bgcolor;\">\\1</span>",
$message);
};
return $message;
};
$message = "some sample text to search and to highlight
and stop";
$search = "to";
print highlight_search(explode(" ", $search),
$message);
?>