I need to find and replace all text matches in a case insensitive way, unless the text is within an anchor tag - for example:
Match this text and re
$a='Match this text and replace it
Don\'t match this text
We still need to match this text and replace it
';
echo preg_replace('~match this text(?![^<]*)~i','replacement',$a);
The negative lookahead ensures the replacement happens only if the next tag is not a closing link . It works fine with your example, though it won't work if you happen to use other tags inside your links.