title: php youtube and links regex are combining and in turn rendering useless
body: <p>i have a posting feature on my site that can embed links and youtube videos. the problem is, that the two clash together, and the youtube iframe ends up being a 404 page on my site. my codes for the youtube videos and links are below, but im not sure how to stop them from combining and ruining it.<br>
  by combining, i mean this <a href="http://www.youtube.com/watch?v=VhqiT2nWCVU" rel="nofollow">http://www.youtube.com/watch?v=VhqiT2nWCVU</a> turns to<br>
  <code>&lt;iframe src="http://www.youtube.com/watch?v=VhqiT2nWCVU"&gt;</code><br>
  which then turns into</p>
  
  <pre><code>&lt;iframe src="&lt;a href="http://www.youtube.com/watch?v=VhqiT2nWCVU"&gt;&lt;/a&gt;"&gt;
  </code></pre>
  
  <p>sorry if i am unclear in any way. my codes are below.</p>
  
  <pre><code>function youtube($string)
  {
    return preg_replace(
      '#(http://(www.)?youtube.com)?/(v/|watch\?v\=)([-|~_0-9A-Za-z]+)&amp;?.*?#i',
      '&lt;iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/$4?rel=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;',
      $string
    );
  }
  
  $posted = youtube($posted);
  
  $rexProtocol = '(https?://)?';
  $rexDomain   = '((?:[-a-zA-Z0-9]{1,63}\.)+[-a-zA-Z0-9]{2,63}|(?:[0-9]{1,3}\.){3}[0-9]{1,3})';
  $rexPort     = '(:[0-9]{1,5})?';
  $rexPath     = '(/[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]*?)?';
  $rexQuery    = '(\?[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?';
  $rexFragment = '(#[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?';
  
  // Solution 1:
  
  function callback($match)
  {
      // Prepend http:// if no protocol specified
      $completeUrl = $match[1] ? $match[0] : "http://{$match[0]}";
  
      return '&lt;a href="' . $completeUrl . '"&gt;'
          . $match[2] . $match[3] . $match[4] . '&lt;/a&gt;';
  }
  
  
  $posted = preg_replace_callback("&amp;\\b$rexProtocol$rexDomain$rexPort$rexPath$rexQuery$rexFragment(?=[?.!,;:\"]?(\s|$))&amp;",
      'callback', $posted);
  </code></pre>