Código PHP:
<?php
function parse_links($str, $len=25, $mid='...'){
$left = ceil(0.6666 * $len);
$right = $len - $left;
preg_match_all('/(?<!=|\]|\/)((https?|ftps?|irc):\/\/|' . '(www([0-9]{1,3})?|ftp)\.)([0-9a-z-]{1,25}' . '[0-9a-z]{1}\.)([^\s&\[\{\}\]]+)/ims', $str, $matches);
foreach($matches[0] as $key=>$value){
$temp = $value;
if(strlen($value) > ($len + strlen($mid) + 2)){
$value = substr($value, 0, $left) . $mid . substr($value,(-1 * $right));
}
$temp = !preg_match('/:\/\//', $temp) ? (substr($temp, 0, 3) === 'ftp' ? 'ftp://' . $temp : 'http://' . $temp) : $temp;
$temp = $temp === $matches[0][$key] && $value === $matches[0][$key] ? '' : '=' . $temp;
$str = str_replace($matches[0][$key],'[url' . $temp . ']' . $value . '[/url]', $str);
}
$str = preg_replace('/\[url=(?!http|ftp|irc)/ims', '[url=http://', $str);
$str = preg_replace('/\[url\](.+?)\[\/url\]/ims','<a href="$1" title="$1">$1</a>',$str);
$str = preg_replace('/\[url=(.+?)\](.+?)\[\/url\]/ims', '<a href="$1" title="$1">$2</a>', $str);
return $str;
}
?>