Replace urls with hyperlinks
Posted: Thu Jul 28, 2005 6:41 pm
Not the best, but an honest effort:
Critiques?
Code: Select all
function addLinks ( $str ) {
$str = preg_replace( "#(http://(?:www\.)?[^\s\.]*\.[^\s$]+)#i" , "<a href=\"$1\" style=\"font-weight: bold;\">$1</a>", $str );
echo preg_replace( "#([^/]www\.[\S$]*)#i" , "<a href=\"http://$1\" style=\"font-weight: bold;\">$1</a>", $str );
}