To be honest, today is the first day I ever touch regular expressions. I'm creating one that will add a target attribute to external links. What I have so far works, but needs a little extra:
$string:
My name is Martin. This is 1 link: <a href="http://www.seacrest.nl/test/">Test</a>. Here's another link <A HREF="../../test.html">Internal</a> and yet another <A href="http://www.testsite.nl/" target="">External</a>
Regex part:
eregi_replace("<a href=\"http://([\"]+)\"([>]*)>([<]+)</a>", "<a href=\"http://\1\" target=\"new\">\3</a>", $string);
What it does so far is add a target to external links, provided they start with http://. However many internal links also start with http:// and then point to www.seacrest.nl/
My question is what do I add to exclude links that have http://www.seacrest.nl in them?
I've tried:
eregi_replace("<a href=\"http://([(www.seacrest.nl)][\"]+)\"([>]*)>([<]+)</a>", "<a href=\"http://\1\" target=\"new\">\3</a>", $string);
But that's just wrong and I know it. Can anyone help me out?
Thanks in advance.