为什么以下代码不缩短此 URL?为什么不把它变成一个实际的可点击 URL?此功能似乎在除此之外的所有其他情况下都有效。
网址:
strongatheism.net/library/atheology/argument_from_noncognitivism/
代码:
function urlfixer($text){
$pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
$callback = create_function('$matches', '
$url = array_shift($matches);
$url_parts = parse_url($url);
$text = parse_url($url, PHP_URL_HOST) . parse_url($url, PHP_URL_PATH);
$text = preg_replace("/^www./", "", $text);
$last = -(strlen(strrchr($text, "/"))) + 1;
if ($last < 0) {
$text = substr($text, 0, $last) . "…";
}
$url = "http://" . str_replace("http://","",$url);
return sprintf(\'<a rel="nofollow" target="_blank" href="%s">%s</a>\', $url, $text);
');
return preg_replace_callback($pattern, $callback, $text);
}