How to convert all url of a string in links with regex?
<p>I found many examples in google but i can't find one script that can get only valid urls.</p>

<p>I found this script:</p>

<pre><code>&lt;?php
function _make_url_clickable_cb($matches)
{
    $url = $matches[2];
    if(empty($url)) return $matches[0];
    return $matches[1]."&lt;a href=\"$url\"&gt;$url&lt;/a&gt;";
}
function _make_web_ftp_clickable_cb($matches)
{
    $dest = $matches[2];
    $dest = 'http://'.$dest;
    if(empty($dest)) return $matches[0];
    return $matches[1]."&lt;a href=\"$dest\"&gt;".$matches[2]."&lt;/a&gt;";
}
function make_clickable($ret)
{
    $ret = preg_replace_callback('#([\s&gt;])([\w]+?://[\w\\x80-\\xff\#$%&amp;~/.\-;:=,?@\[\]+]*)#is', '_make_url_clickable_cb', $ret);
    $ret = preg_replace_callback('#([\s&gt;])((www)\.[\w\\x80-\\xff\#$%&amp;~/.\-;:=,?@\[\]+]*)#is', '_make_web_ftp_clickable_cb', $ret);
    $ret = preg_replace("#(&lt;a( [^&gt;]+?&gt;|&gt;))&lt;a [^&gt;]+?&gt;([^&gt;]+?)&lt;/a&gt;&lt;/a&gt;#i", "$1$3&lt;/a&gt;", $ret);
    $ret = trim($ret);
    return $ret;
}
echo make_clickable('I have some texts here and also links such as http://www.youtube.com , www.apcsoftware.com.br/home/?produtos and lol@example.com. They are ready to be replaced.');
?&gt;
</code></pre>

<p>but it convert invalid urls like: <a href="http://www.youtube" rel="nofollow">http://www.youtube</a>. com but it convert only <a href="http://www.youtube" rel="nofollow">http://www.youtube</a>. , i would like to urls like it not get converted.</p>

<p>someone got some script that can do it?</p>

<p>thanks.</p>
