Archive

Posts Tagged ‘regex’

RegEx to find URLs and turn them into hyperlinks

July 13th, 2008
 
$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? :-)

Popularity: 17% [?]

PHP, Web development ,