PDA

View Full Version : php question - urls



invalid
March 24th, 2002, 12:50
i'm wondering if anybody knows how to convert urls from http://www.something.com to <a href="http://www.something.com">http://www.something.com</a> for use in my forum

invalid
March 24th, 2002, 13:21
nevermind.


function make_clickable($text)
{
$ret = " " . $text;
$ret = preg_replace("#([\n ])([a-z]+?)://([^,\t \n\r]+)#i", "\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", $ret);
$ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^,\t \n\r]*)?)#i", "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>", $ret);
$ret = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
$ret = substr($ret, 1);
return($ret);
}

i used that... it converts www.asdsad.com's to html links