Hey everyone. 🙂 What I'm trying to do is automatically turn links into clickable hyperlinks, but only if they are not wrapped already in the BBCode tag . If that makes sense.
So if a user enters an URL like:
http://somesitesomewhere.com/
it would automatically be parsed. However if a user enters a link using BBCode, it would ignore it because that already gets parsed by the BBCode parser.
So
[url=http://somesitesomewhere.com/]some site[/url]
and it's entirety would be ignored. Could someone please help me with the conditions? It'd be very much appreciated. 🙂 Here's what I'm working with at the moment:
function autoLink($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','<a href="\\1">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1<a href="http://\\2">\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1">\\1</a>', $text);
return $text;
}