Why doesn't the following code shorten this URL? And why doesn't it turn it into an actual clickable URL? This function seems to work in all other cases but this one.
URL:
strongatheism.net/library/atheology/argument_from_noncognitivism/
Code:
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);
}