PHP convert URL into a link
13 Aug 2010 by Steve
A small code snippet used to convert URLs into HTML live links with PHP. Useful for when creating a user comments post box.
$str = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href="\0">\0</a>", $str);
If your using this for a comments section or forum you may want to add the rel=nofollow attribute so the google bot will ignore the link.
$str =
ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a
href="\0" rel="nofollow">\0</a>", $str);
Comments
Posted 15 Feb 2012

