Ver Mensaje Individual
  #6 (permalink)  
Antiguo 30/06/2009, 08:28
Kadmon
 
Fecha de Ingreso: noviembre-2007
Mensajes: 19
Antigüedad: 16 años, 5 meses
Puntos: 0
Respuesta: Acortar direcciones

Pues ¡Lo conseguí!.

Este es el código, recordad cambiar "hxp" y "wxw" por su forma correcta

Código PHP:
function make_links_blank($noticia)
{
return 
preg_replace(
array(
'/(?(?=<a[^>]*>.+<\/a>)
(?:<a[^>]*>.+<\/a>)
|
([^="\']?)((?:hxps?|ftp|bf2|):\/\/[^<> \n\r]+)
)/iex'
,
'/<a([^>]*)target="?[^"\']+"?/i',
'/<a([^>]+)>/i',
'/(^|\s)(wxw.[^<> \n\r]+)/iex',
'/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)
(\\.[A-Za-z0-9-]+)*)/iex'
),
array(
"stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\" rel=\"notfollow\">'.substr(\"\\2\",0,35).'</a>\\3':'\\0'))",
'<a\\1',
'<a\\1 target="_blank">',
"stripslashes((strlen('\\2')>0?'\\1<a href=\"hxp://\\2\" rel=\"notfollow\">'.substr(\"\\2\",0,35).'</a>\\3':'\\0'))",
"stripslashes((strlen('\\2')>0?'<a href=\"mailto:\\0\">\\0</a>':'\\0'))"
),
$noticia
);
}
echo 
nl2br (make_links_blank($noticia)); 
Un saludo

Edit: la solución estaba en añadir '.substr(\"\\2\",0,35).' (primera y cuarta línea del segundo array)

Última edición por Kadmon; 30/06/2009 a las 11:55