I am facing a problem searching words in a string and converting them into links. How to make a search that considers words containing a "-" as whole word and not as 2 words separated by "-" ?
Here is an example, if I search for the word "exhaustive", my search function will also match the part of the word "non-exhaustive", although i don't want this word to be matched.
$string = "Bla bla bla non-exhaustive blabla bla exhaustive";
$words = array('exhaustive','non-exhaustive');
foreach ($words as $word) {
$string = preg_replace('/\b'.$word.'\b/i', '<a href=#>'.$word.'</a>',$string);
}
echo $string;
Result :
Bla bla bla non-exhaustive blabla bla exhaustive
Thank you very much for your help !