把字符串中的url替换成可点击的链接,默认给链接添加nofollow,即不允许搜索引擎搜索
function replace_urls($string, $rel = 'nofollow'){
$host = "([a-z\d][-a-z\d]*[a-z\d]\.)+[a-z][-a-z\d]*[a-z]";
$port = "(:\d{1,})?";
$path = "(\/[^?<>\#\"\s]+)?";
$query = "(\?[^<>\#\"\s]+)?";
return preg_replace("#((ht|f)tps?:\/\/{$host}{$port}{$path}{$query})#i", "<a href=\"$1\" rel=\"{$rel}\">$1</a>", $string);
}
