Código PHP:
Ver original
function textToLink($subject){ $pattern = "/(?i)\b(((http|https|ftp):\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))/"; return $text; }
Esa funcion anda bien de esta manera
Código PHP:
Ver original
$subject = 'link1 http://www.youtube.com/watch?v=CkSdiBltgYo&feature=fvwrel<br> link2 www.youtube.com/watch?v=CkSdiBltgYo&feature=fvwrel<br> link3 https://www.youtube.com/watch?v=CkSdiBltgYo&feature=fvwrel<br> link4 ftp://youtube.com/watch?v=CkSdiBltgYo&feature=fvwrel<br> link5 snipplr.com/view/64247/'; $texto = textToLink($subject);
Funciona bien para los 4 primeros links, pero para el 5 retorna
Código HTML:
y necesito que me retorneVer original
Código HTML:
Ver original
He tratado con varias expresiones regulares que me verifican si existe un a href sin http, ftp o https, pero a la hora de remplazarlo no funciona como espero
Código PHP:
Ver original
preg_replace('/(?i)\b(<a href="[^http:\/\/]|[^https:\/\/]|[^ftp:\/\/][a-z0-9.\-]+[.]")/',"<a href=\"http://$1\" target=\"_blank\">$1</a>",$text)
Hay alguna sugerencia de como hacerlo?
Saludos