Possible Duplicate:
How do I linkify urls in a string with php?
It would be so delightful if I could overcome this problem once and for all.
I need to able to create urls from strings like http://www.google.com
and also www.google.com
function hyperlink($text)
{
// match protocol://address/path/
$text = ereg_replace("[a-zA-Z]+://([.]?[a-zA-Z0-9_/-])*", "<a href=\"\\0\">\\0</a>", $text);
// match www.something
$text = ereg_replace("(^| )(www([.]?[a-zA-Z0-9_/-])*)", "\\1<a href=\"http://\\2\">\\2</a>", $text);
// return $text
return $text;
}