I have a function I found at www.phpwizard.net for finding URLs in a string and making them into clickable links. However, the function will also find URLs that already reside in a valid HREF tag.
Here is the function I am using:
// finds URLs in basic text and makes them into clickable links
function make_clickable( $text ) {
$ret = eregi_replace(" ([[:alnum:]]+)://([[:space:]])([[:alnum:]#?/&=])", "<a href=\"\1://\2\3\" target=\"_blank\" target=\"_new\">\1://\2\3</a>", $text);
$ret = eregi_replace(" (([a-z0-9_]|\-|\.)+@([[:space:]])([[:alnum:]-]))", "<a href=\"mailto:\1\" target=\"_new\">\1</a>", $ret);
return($ret);
}
This particular function has two problems. The first is described above, (it converts URLS already properly clickable) and the second is it will not work if the URL is the first item in the string, or immediately follows a carriage return.
Could somebody help me out with making this so it would not find URLs already embedded in an HREF tag, and will work if the URL is either the first item in the string or immediately follows a carriage return or linefeed....
Thanx!