title: PHP DOMDocument - ignore unexpected closing tags
body: <p>I'm kind of hacking my WordPress theme footer, and I found a little problem.</p>
  
  <p>What I am doing is taking the footer of the parent theme, capturing the output, and using DOMDocument to modify an element. Here is my code:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  // I apologize in advance for my messy code....
  
  /**
  * JavaScript-like HTML DOM Element
  *
  * This class extends PHP's DOMElement to allow
  * users to get and set the innerHTML property of lalalalala....
  *
  * @author Keyvan Minoukadeh - http://www.keyvan.net - keyvan@keyvan.net
  * @see http://fivefilters.org (the project this was written for)
  */
  // blahblahblah
  
  ob_start();
  require get_theme_root() . '/responsive/footer.php';
  $output = ob_get_clean();
  
  libxml_use_internal_errors(true);
  
  $dom = new DOMDocument();
  $dom-&gt;registerNodeClass('DOMElement', 'JSLikeHTMLElement');
  $dom-&gt;loadHTML($output);
  $finder = new DomXPath($dom);
  $classname="powered";
  $nodes = $finder-&gt;query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]");
  $elem = $nodes-&gt;item(0);
  
  $elem-&gt;innerHTML = "hahaha..gotcha!";
  
  echo $dom-&gt;saveHTML();
  ?&gt;
  </code></pre>
  
  <p>However, the footer output contains two <code>&lt;/div&gt;</code>s (unexpected closing tags) and that is making DOMDocument complain. In fact, it just gets rid of those <code>&lt;/div&gt;</code>s and makes the page look weird. I can't just add <code>&lt;/div&gt;&lt;/div&gt;</code> to the beginning of the output because there is stuffing around the <code>&lt;/div&gt;</code>s.</p>
  
  <p>Is there a way to get DOMDocument to ignore those unexpected tags and leave them there or should I use a different library?</p>