I'm having trouble putting together the proper RegEx pattern to add target="_blank" to my links. To add that to all links.. no problem, but I need to exclude certain instances based on the pattern.
This is the preg_replace() I'm using to update ALL links with target that are showing http:// in the href
preg_replace('/(<a href="http:[^"]+")>/is','\\1 target="_blank">',$content);
Here are scenarios I'm trying to get
link1 /somepage.htm (no target="_blank") Above works
link2 http://www.somesiteexternal.com/ (add target="_blank") Above works
link3 http://www.example.com/somepage.htm (no target="_blank") this is where I'm having a problem.
I want to exclude http://www.example.com or http://example.com (which would be the domain where the code lives) from the target handling, but if the link is an absolute link or to another external site that is NOT using domain.com then I want that.
Trying to add the exclude/exception pattern in this (<a href="http:[^"]+")
is giving me trouble.
Thanks! hanji