I am aware that regex is not ideal for use with HTML strings and I have looked at the PHP Simple HTML DOM Parser but still believe this is the way to go. All the HTML tags w
Using the DOM would certainly be preferable.
However, you might get away with this:
$result = preg_replace('%Amazon(?![^<]*)%i', 'Amazon', $subject);
It matches Amazon only if
tag, tags.It will therefore change this:
I use Amazon for that.
I use Amazon for that.
My Amazon Link
It will match the "Amazon" in "My Amazon Link"
into this:
I use Amazon for that.
I use Amazon for that.
My Amazon Link
It will match the "Amazon" in "My Amazon Link"