RegEx to find URLs and turn them into hyperlinks
$string = preg_replace("/(http:\/\/)?([a-zA-Z0-9\-.]+\.[a-zA-Z0-9\-]+([\/]([a-zA-Z0-9_\/\-.?&%=+])*)*)/", '<a href="http://$2">$2</a>', $string);
That little gem right there'll take any length of text and turn the urls in it into hyperlinks. Cool or what? :-)

Posted in PHP, Web development at July 13th, 2008. Trackback URI: trackback
Tags: regex, regular expressions
Tags: regex, regular expressions