Ver Mensaje Individual
  #5 (permalink)  
Antiguo 19/05/2008, 12:46
Surfiction
 
Fecha de Ingreso: enero-2008
Mensajes: 132
Antigüedad: 16 años, 3 meses
Puntos: 6
Respuesta: Convertir texto a enlace

Código PHP:

function links($x)
    {
    return 
preg_replace(
        array(
        
'/(?(?=<a[^>]*>.+<\/a>)
        (?:<a[^>]*>.+<\/a>)
        |
        ([^="\']?)((?:https?|ftp|bf2|):\/\/[^<> \n\r]+)
        )/iex'
,
        
'/<a([^>]*)target="?[^"\']+"?/i',
        
'/<a([^>]+)>/i',
        
'/(^|\s)(www.[^<> \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\">\\2</a>\\3':'\\0'))",
        
'<a\\1',
        
'<a\\1 target="_blank" rel="nofollow" class="link">',
        
"stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\"  target=\"_blank\" rel=\"nofollow\" class=\"link\">\\2</a>\\3':'\\0'))",
        
"stripslashes((strlen('\\2')>0?'<a href=\"mailto:\\0\">\\0</a>':'\\0'))"
            
),
    
$x
    
);
    } 
Suerte