0
爲什麼下面的代碼不能縮短這個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);
}