How to make links clickable <a> tags in PHP

A simple function will turn all your links into clickable a tags that take you to the source of the link. The caveat? This function will only convert address's that start with www or ftp, and there can be no characters before the beginning or end (except whitespace). At some point, I'll update this script to be a bit more realistic and flexible. I found it off the net:


function make_href( $text ){

    $ret = ' ' . $text;

    $ret = preg_replace("#(^|[\n ])([\w]+
    ?://[\w]+[^ \"\n\r\t<]*)#ise", "'\\1\\2'", $ret);

    $ret = preg_replace("#(^|[\n ])
    ((www|ftp)\.[^ \"\t\n\r<]*)#ise",
    "'\\1\\2'", $ret);

    $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)
    @([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1
    \\2@\\3", $ret);

    $ret = substr( $ret, 1 );

    return( $ret );
}