Esta función convierte las URL y direcciones de correo electrónico dentro de una cadena en hpervículos "clikables".
<?php
function CrearLinks($texto) {
$texto = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $texto);
$texto = ' ' . $texto;
$texto = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $texto);
$texto = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $texto);
$texto = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $texto);
$texto = substr($texto, 1);
return $texto;
}
$cadena ="Lorem ipsum www.google.es. Qui, webintenta@gmail.com repren.";
echo CrearLinks($cadena);
?>
Visto en How To Make Clickable Text URL Links From Text Links Change To Clicking » »




