title: change youtube url to embed url in php
body: <p>I found this code (<a href="https://stackoverflow.com/questions/10435645/swap-all-youtube-urls-to-embed-via-preg-replace">Swap all youtube urls to embed via preg_replace()</a>) to swap youtube urls (<a href="http://www.youtube.com/watch?v=CfDQ92vOfdc" rel="nofollow noreferrer">http://www.youtube.com/watch?v=CfDQ92vOfdc</a>, or <a href="http://www.youtube.com/v/CfDQ92vOfdc" rel="nofollow noreferrer">http://www.youtube.com/v/CfDQ92vOfdc</a>) into youtube embed urls (<a href="http://www.youtube.com/embed/CfDQ92vOfdc" rel="nofollow noreferrer">http://www.youtube.com/embed/CfDQ92vOfdc</a>) but it doesn't seem to be working? Any ideas? I don't know much about regular expression.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>$string     = 'http://www.youtube.com/watch?v=CfDQ92vOfdc';
  $search     = '#&lt;a (?:.*?)href=["\\\']http[s]?:\/\/(?:[^\.]+\.)*youtube\.com\/(?:v\/|watch\?(?:.*?\&amp;)?v=|embed\/)([\w\-\_]+)["\\\']#ixs';
  $replace    = 'http://www.youtube.com/embed/$2';
  $url        = preg_replace($search,$replace,$string);
  </code></pre>
  
  <p>but it's still displaying as:</p>
  
  <pre><code>http://www.youtube.com/watch?v=CfDQ92vOfdc
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>http://www.youtube.com/embed/CfDQ92vOfdc
  </code></pre>
  
  <p>Thanks in advance.</p>