Given the following simple function (for a PHP page) I am trying to match all the occurences of the word $marker
in a long text string. I need to highlight its occurences.
The function works, but it presents two problems:
1) it fails to match uppercase occurences of $marker
2) it also matches partial occurences: if $marker is "art", the function as it is also matches "artistic" and "cart".
How can I correct these two inconveniences?
function highlightWords($string, $marker){
$string = str_replace($marker, "<span class='highlight success'>".$marker."</span>", $string);
return $string;
}