title: How do I parse partial HTML?
body: <p>I'm trying to parse some HTML with DOM in PHP, but I'm having some problems. First, in case this change the solution, the HTML that I have is not a full page, rather, it's only part of it.</p>
  
  <pre><code>&lt;!-- This is the HTML that I have --&gt;&lt;a href='/games/'&gt;
  &lt;div id='game'&gt;
  &lt;img src='http://images.example.com/games.gif' width='300' height='137' border='0'&gt;
  &lt;br&gt;&lt;b&gt; Game &lt;/b&gt;
  &lt;/div&gt;
  &lt;div id='double'&gt;
  &lt;img src='http://images.example.com/double.gif' width='300' height='27' border='0' alt='' title=''&gt;
  &lt;/div&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>Now I'm trying to get only the div with the id <code>double</code>. I've tried the following code, but it doesn't seem to be working properly. What might I be doing wrong?</p>
  
  <pre><code>//The HTML has been loaded into the variable $html
  $dom=new domDocument;
  $dom-&gt;loadHTML($html);
  $dom-&gt;preserveWhiteSpace = false; 
  $keepme = $dom-&gt;getElementById('double'); 
  
  $contents = '&lt;div style="text-align:center"&gt;'.$keepme.'&lt;/a&gt;&lt;/div&gt;';
  echo $contents;
  </code></pre>