boeing747fp
11-01-2007, 05:04 AM
function findLinks($string){
// link URLs
$string =
eregi_replace("(([[:alnum:]]+://)|www\.)([^[:space:]]*)([[:alnum:]#?/&=])", "<a target=\"_blank\" href=\"\\1\\3\\4\" title=\"Go to \\1\\3\\4\">\\1\\3\\4</a> ", $string);
// fix lazy URLs
$string = eregi_replace("href=\"www","href=\"http://www", $string);
// link mailtos
$string = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))",
"<a href=\"mailto:\\1\" title=\"E-mail \\1\">\\1</a> ", $string);
// truncates long urls that can cause display problems
$string =
preg_replace("/>(([[:alnum:]]+:\/\/)|www\.)([^[:space:]]{30,40})([^[:space:]]*)([^[:space:]]{10,20})([[:alnum:]#?\/&=])</",
">\\1\\3...\\5\\6<", $string);
$string = stripslashes($string);
return $string;
}
this seems to work really well as long as someone has a space after the URL (it doesnt work if someone has a linebreak after a URL)... it just doesnt put </a> before <br> :(
// link URLs
$string =
eregi_replace("(([[:alnum:]]+://)|www\.)([^[:space:]]*)([[:alnum:]#?/&=])", "<a target=\"_blank\" href=\"\\1\\3\\4\" title=\"Go to \\1\\3\\4\">\\1\\3\\4</a> ", $string);
// fix lazy URLs
$string = eregi_replace("href=\"www","href=\"http://www", $string);
// link mailtos
$string = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))",
"<a href=\"mailto:\\1\" title=\"E-mail \\1\">\\1</a> ", $string);
// truncates long urls that can cause display problems
$string =
preg_replace("/>(([[:alnum:]]+:\/\/)|www\.)([^[:space:]]{30,40})([^[:space:]]*)([^[:space:]]{10,20})([[:alnum:]#?\/&=])</",
">\\1\\3...\\5\\6<", $string);
$string = stripslashes($string);
return $string;
}
this seems to work really well as long as someone has a space after the URL (it doesnt work if someone has a linebreak after a URL)... it just doesnt put </a> before <br> :(