title: Regex YouTube IFRAME
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php">How to parse and process HTML with PHP?</a>  </p>
  </blockquote>
  
  
  
  <p>I want to publish an app for android (wordpress blog). The app displays also some YouTube videos.
  I need a method to replace YouTube IFRAMES + EMBED-Codes (old embed method) with an a - tag:</p>
  
  <pre><code>&lt;iframe ...
  
  
  &lt;a href="http://www.youtube.com/watch?v=id"&gt;&lt;img src="http://i1.ytimg.com/vi/id/hqdefault.jpg" /&gt;&lt;/a&gt;
  </code></pre>
  
  <p>The replacement: either via php (server) or via java (eclipse). I have only found some snippets...</p>
  
  <pre><code>/embed\/([a-zA-Z0-9_-]{11})/
  </code></pre>
  
  <p>But how could I use it? Please help me!</p>
  
  <p><strong>EDIT:</strong> I try to replace the following CODE:</p>
  
  <pre><code>&lt;iframe width="560" height="315" src="http://www.youtube.com/embed/**ID**" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>@Stephan</p>
  
  <pre><code>$content = "contains &lt;iframe... and article"
  $search = '/&lt;iframe.+?src="http://www.youtube.com/embed/([a-zA-Z0-9_-]{11})"[^&gt;]+?&gt;&lt;/iframe&gt;/i';
  $replace = '&lt;a href="http://www.youtube.com/watch?v=$1"&gt;&lt;img src="http://i1.ytimg.com/vi/$1/hqdefault.jpg" /&gt;&lt;/a&gt;';
  $content = preg_replace($search, $replace, $content);
  echo $content;
  </code></pre>
  
  <p>How could I used it? Error: Unknown modifier '/' (in PHP).</p>