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
Use this code:
$p = '~((]*?>))?(amazon)~smi';
$str = 'Amazon';
$s = preg_replace($p, "$1My $3 Link", $str);
var_dump($s);
String(50) "My Amazon Link"