title: DOMDocument expands first tag
body: <p><strike>I am trying to add attributes to document nodes with DOMDocument.</strike> <em>This is not part of the problem.</em>
  Unfortunately, the first tag in my html is expanded to span the entire document.</p>
  <p>The problem can be seen in this example:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  $html = &quot;&lt;h3&gt;HEADING&lt;/h3&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;lorem ipsum&lt;/p&gt;&quot;;
  
  $doc = new DOMDocument();
  
  // prevent warning and errors when loading html 
  libxml_use_internal_errors(true);
  
  // load html, convert to utf-8, prevent appending &quot;&lt;html&gt;&quot; headers
  $doc-&gt;loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
      
  var_dump($doc-&gt;saveHTML());
  </code></pre>
  <p>(Interactive here: <a href="https://3v4l.org/ddQZ9" rel="nofollow noreferrer">https://3v4l.org/ddQZ9</a>)</p>
  <p>This code generates this output:</p>
  <pre><code>string(48) &quot;&lt;h3&gt;HEADING&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;lorem ipsum&lt;/p&gt;&lt;/h3&gt;&quot;
  </code></pre>
  <p>which is not what I intended, since the <code>&lt;h3&gt;</code> tag now spans all the html.</p>
  <p>How can I prevent this behavior?</p>