Código PHP:
function ConvertirCortarurl( $matches ) {
$limite = 40;
$matches[0] = (strlen($matches[0]) > $limite) ? substr($matches[0],0,15)."...".substr($matches[0],19-$limite) : $matches[0];
return "<a href=\"".(!empty($matches[3]) ? $matches[3] : "http")."://$matches[4]$matches[5]$matches[6]\" target=\"_blank\">$matches[0]</a>";
}
function ConvertirCortaremail( $matches ) {
$limite = 40;
$matches[0] = (strlen($matches[0]) > $limite) ? substr($matches[0],0,15)."...".substr($matches[0],19-$limite) : $matches[0];
return "<a href=\"mailto:$matches[1]@$matches[2].$matches[3]\">$matches[0]</a>";
}
function ponerLinksurl( $str ) {
return preg_replace_callback("/((([a-zA-Z]+):\/\/)|(www\.))([\w\.]+)([\#\,\/\~\?\&\=\;\%\-\w+\.]+)/i",'ConvertirCortarurl',$str);
}
function ponerLinksemail( $str ) {
return preg_replace_callback("/([\w\._-]+)@([\w]+)\.([\w\._-]+)/i",'ConvertirCortaremail',$str);
}
$comentario = ponerLinksemail(ponerLinksurl($comentario));