Remplazar Url por un link con php

function convertirURL($url)
{
$host = «( [a-z\d] [-a-z\d] * [a-z\d] \.)+ [a-z] [-a-z\d] * [a-z] «;
$port = «(:\d{1,})?»;
$path = «(\/ [^?<>\#\»\s] +)?»;
$query = «(\? [^<>\#\»\s] +)?»;

$reg = «#((ht|f)tps?:\/\/{$host}{$port}{$path}{$query})#i»;
return preg_replace($reg, «<a href=’$1′>$1</a>», $url);
}
//ejm:
echo convertirURL(» visita http://www.google.com»);