Extract urls in text
<p>Let say we've text with more than one url within, so i would like to extract that url and doing some changes then shows up the text.</p>

<p>Here is the code i'm using</p>

<pre><code>&lt;?PHP
$text = "This is text with links http://google.com and www.yahoo.com";

$text = ereg_replace( "www\.", "http://www.", $text );
$text = ereg_replace( "http://http://www\.", "http://www.", $text );
$text = ereg_replace( "https://http://www\.", "https://www.", $text );

$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

if(preg_match($reg_exUrl, $text, $url)) {

$text = preg_replace($reg_exUrl, '&lt;a href="'.$url[0].'" rel="nofollow"&gt;'.$url[0].'&lt;/a&gt;', $text);
echo $text;

}else{

echo "NO URLS";

}
?&gt;
</code></pre>

<p><strong>The problem</strong></p>

<p>// output source (repeat for first link)</p>

<pre><code>This is text with links &lt;a href="http://google.com" rel="nofollow"&gt;http://google.com&lt;/a&gt; and &lt;a href="http://google.com" rel="nofollow"&gt;http://google.com&lt;/a&gt;
</code></pre>

<p>It depends on array so it only takes the first URL <code>$url[0]</code> so how can i apply for all links to be found within the text ~ Thanks</p>
