Convert URLs to links automatically with PHP
Lots of blogs and things about this kicking around - many complicated, many just don't work. This seemed to do the trick for me:
public static function ParseURL($text) { $text = preg_replace('`www.S+`', 'http://{0}', $text); $text = preg_replace('`[a-z]{3,6}://S+.S*`', '$0', $text); return $text; } public static function ParseEmail($text) { return preg_replace('`[w.-]+@w+[w.-]*?.w{1,4}`im', '$0', $text); }