title: PHP Replace multiple URL's in text with anchor tags
body: <p>I have tried following so far:</p>
  
  <pre><code>&lt;?php
  
  // The Regular Expression filter
  $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
  
  $text = "The text I want to filter is here. It has urls http://www.example.com and http://www.example.org";
  
  // Check if there is a url in the text
  if(preg_match($reg_exUrl, $text, $url)) {
  
         // make the urls hyper links
         $final = preg_replace($reg_exUrl, "&lt;a href=\"{$url[0]}\"&gt;{$url[0]}&lt;/a&gt; ", $text);
  
         echo $final;
  
  } else {
         // if no urls in the text just return the text
         echo $text;
  }
  </code></pre>
  
  <p>The only issue I am facing is that this is replacing both the URL's with the same url(that is the one found first). How do I <code>loop</code> this to replace each url with their own?</p>