Forum Moderators: coopster
I'm trying to convert non clickable urls in a string into clickable urls (and add target="_blank" to the links). The preg_match / ereg pattern should ignore any urls that are already clickable (ie: the ones with <a href="..">..</a> tags).
Here's what I've come up with so far:
-------------------------
$linkstarget = "_blank";
$text = 'A clickable link: <a href="http://www.domain.com/test/test.html">clickable</a> and a non clickable link: [domain.com';...]
$replace = "<a href=\"\\2\" target=\"".$linkstarget."\">\\3</a>";
$text = eregi_replace('(<a [^<]*href=["¦\']?([^ "\']*)["¦\']?[^>]*>([^<]*)</a>)',$replace, $text);
echo $text;
-----------------------
It adds the target="_blank" part to the link that was already clickable, but now I need something that finds the non clickable link ONLY and adds the <a href="..">..</a> tags. It's very important that it will only find the non clickable url, otherwise it will also add href tags to the already clickable url.
Any help would be greatly appreciated!
Leon
I think a look behind assertion [php.net] may be what you are wanting. I don't have time to throw down a regex right now, but the PHP manual pages might get you started in the right direction.
Give it your best effort and we'll have a look if you get stuck!