第一個
$text = eregi_replace("([^=\"])(http|ftp|gopher://[^ \n\r]+(?=[\s\.,]))","\\1<a href=\"\\2\" target=_top>\\2</a>", $text);
第二個
$comment = eregi_replace("([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]
{2,3})","<a href=\"mailto:\\1\">\\1</a>", $comment);
抄個煩點的齊全板版
function buildHyperlinks($string) {
$httpurl =
"(((f|ht){1}tp://)[a-zA-Z0-9@:%_.~#-\?&]+[a-zA-Z0-9@:%_~#\?&])";
$wwwsurl =
"(([[:space:]+]|^)(www[.][a-zA-Z0-9@:%_.~#-\?&]+[a-zA-Z0-9@:%_~#\?&]))";
$mailurl =
"([-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+)";
$parts = explode(" ", $string);
for($i = 0; $i < sizeof($parts); $i++) {
if(eregi($httpurl, $parts[$i])) {
$temp = $parts[$i];
$parts[$i] = eregi_replace($httpurl, "<a href=\"\\1\"
target=\"_blank\">", $parts[$i]);
$parts[$i] .= "$temp</a>";
}
if(eregi($wwwsurl, $parts[$i])) {
$temp = $parts[$i];
$parts[$i] = eregi_replace($wwwsurl, "\\2<a
href=\"http://\\3\" target=\"_blank\">", $parts[$i]);
$parts[$i] .= "$temp</a>";
}
if(eregi($mailurl, $parts[$i])) {
$temp = $parts[$i];
$parts[$i] = eregi_replace($mailurl, "<a
href=\"mailto:\\1\">", $parts[$i]);
$parts[$i] .= "$temp</a>";
}
}
return join(" ", $parts);
}
|