function url2hyperlink($text) { $pattern = '#(^|[^\"=]{1})(http://|ftp://|mailto:|news:)([^\s<>]+)([\s\n<>]|$)#sm'; $text = preg_replace($pattern,"\\1\\2\\3\\4",$text); return $text; }