bold all text except links
Posted: Mon Jul 27, 2009 4:46 am
Hello,
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:
Currently, we are using:
$new_string = str_replace($search_term, "<b>".$search_term."</b>", $old_string);
But this, of course, makes the string this:
Note the 'dog' part in the URL is broken. Therefore when people click on the link, the link is broken as there is no such page as /<b>dog</b>-walking.html
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
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