Auto Link HTML In PHP
Join the DZone community and get the full member experience.
Join For Free// linkify URLs in a block of text.
function make_clickable($text)
{
$ret = ' ' . $text;
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", "'\\1\\2'", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise", "'\\1\\2'", $ret);
$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1\\2@\\3", $ret);
$ret = substr($ret, 1);
return($ret);
}
PHP
HTML
Opinions expressed by DZone contributors are their own.
Comments