We have a bit of code that bolds a key term within a given block of text (eg. from a search result).
It's working fine, except sometimes, the text can contain a link.
Say $search_term is "dog", and $old_string is:
Code: Select all
A lot of dogs are happy to go for a walk. You may prefer our <a href="/dog-walking.html">Dog Walking Page</a>.$new_string = str_replace($search_term, "<b>".$search_term."</b>", $old_string);
But this, of course, makes the string this:
Code: Select all
A lot of <b>dog</b>s are happy to go for a walk. You may prefer our <a href="/<b>dog</b>-walking.html"><b>Dog</b> Walking Page</a>.How can we write the code so that the term is highlighted in bold, but NOT if the term is appearing in a link?
Thanks for your help.
Rich