Ver Mensaje Individual
  #2 (permalink)  
Antiguo 30/12/2011, 05:00
feeeeeR
 
Fecha de Ingreso: abril-2011
Mensajes: 18
Antigüedad: 13 años
Puntos: 1
Respuesta: expresiones regulares - Url a enlace

He encontrado por fín una función que va!

sería algo así:

Código PHP:
    function texto_a_url($text){
        
// pad it with a space so we can match things at the start of the 1st line.
        
$ret ' ' $text;
 
        
// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
        // xxxx can only be alpha characters.
        // yyyy is anything up to the first space, newline, comma, double quote or <
        
$ret preg_replace("#([\t\r\n ])([a-z0-9]+?){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i"'\1<a href="\2://\3" target="_blank">\2://\3</a>'$ret);
 
        
// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
        // Must contain at least 2 dots. xxxx contains either alphanum, or "-"
        // zzzz is optional.. will contain everything up to the first space, newline,
        // comma, double quote or <.
        
$ret preg_replace("#([\t\r\n ])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i"'\1<a href="http://\2.\3" target="_blank" rel="nofollow">\2.\3</a>'$ret);
 
        
// matches an email@domain type address at the start of a line, or after a space.
        // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".

        // Remove our padding..
        
$ret substr($ret1);
 
        return(
$ret);
    } 
Voy a ver si puedo conseguir que los @nicktwitter los pase a un enlace a <a href="http://twitter.com/nicktwitter">Nicktwitter</a>