title: PHP: Preg_match and replace all
body: <p>I have an obvious hyperlink which I all want to replace in a text to just normal HTML hyperlinks.
  So this just works for one hyperlink:</p>
  
  <pre><code>$string = '&lt;u&gt;\\n\\\\*HYPERLINK \\"http://www.youtube.com/watch?v=A0VUsoeT9aM\\"A Youtube Video&lt;/u&gt;';
  $pattern = '/http[?.:=\\w\\d\\/]*/';
  $namePattern = '/(?:")([\\s\\w]*)&lt;/';
  preg_match($pattern, $string, $matches);
  preg_match($namePattern, $string, $nameMatches);
  
  echo '&lt;a href="'.$matches[0].'"&gt;'.$nameMatches[1].'&lt;/a&gt;';
  </code></pre>
  
  <p>But there are more hyperlinks than just one in a text so I want to just change all of these hyperlinks:</p>
  
  <pre><code> &lt;?php 
      $input = 'Blablabla Beginning Text &lt;u&gt;\\n\\\\*HYPERLINK \\"http://www.youtube.com/watch?v=A0VUsoeT9aM\\"1.A Youtube Video&lt;/u&gt; blablabla Text Middle &lt;u&gt;\\n\\\\*HYPERLINK \\"http://www.youtube.com/watch?v=A0VUsoeT9aM\\"2. A Youtube Video&lt;/u&gt; blabla Text after';
      //To become:
      $output = 'Blablabla Beginning Text &lt;a href="http://www.youtube.com/watch?v=A0VUsoeT9aM"&gt;1. A Youtube Video&lt;/a&gt;blablabla Text Middle &lt;a href="http://www.youtube.com/watch?v=A0VUsoeT9aM"&gt;2. A Youtube Video&lt;/a&gt; blabla Text after';
      ?&gt;
  </code></pre>
  
  <p>How would I do that?</p>