Excellent. Those examples were helpful. This pattern effectively prevents matches inside of tags:
$pattern = "/\b($word)\b(?=([^>]*<))/i";
Almost there. This pattern will match words that occur between an opening and closing <a> tag, e.g. this --
$string = "Hey there <a href="www.john.com">John Simpson</a>.";
$word = "john";
$pattern = "/\b($word)\b(?=([^>]*<))/i";
$replacement = "<u>\\1</u>";
$newString = preg_replace ( $pattern, $replacement, $string );
echo $newString;
-- gives me this:
Hey there <a href="www.john.com"><u>John</u> Simpson</a>.
I can't have replacements between the opening and closing <a> tags either. Basically, I can't have any replacements between <a.......</a>, but I'm not sure how to use regex to say match $word unless it occurs between <a.....</a>.
Any ideas?