title: PHP Warning DOMDocument::loadHTML(): Tag section invalid in Entity on line 10
body: <p>Here is line 10:</p>
  
  <pre><code>$doc-&gt;loadHTML('&lt;?xml encoding="utf-8" ?&gt;'.$request-&gt;getData());
  </code></pre>
  
  <p>And here is the whole code snippet from my backend:
      
  
  <pre><code>class ParseImageLinks{
  public function __construct(){
  }
  
  public function Run(\DataLayer\Gallery\Requests\ParseImageLinks $request){
      $doc = new \DOMDocument('1.0');
      $doc-&gt;loadHTML('&lt;?xml encoding="utf-8" ?&gt;'.$request-&gt;getData());
  
      $images = $doc-&gt;getElementsByTagName ( "img");
  
      foreach ($images as $key =&gt; $value){
          $src = $value-&gt;getAttribute("src");
          $local = false;
  
          if ($src[0] == 'h') {
              $src = explode("http://", $src)[1];
          }else{
              if ($src[0] == '/') {
                  $src = substr($src,1);
                  $local = true;
              }
          }
  
          $parse = explode('/', $src);
          if (count($parse) &gt; 2 &amp;&amp; ($local || $parse[0] == $_SERVER['SERVER_NAME'] || $parse[0] == 'localhost:8080')) {
              $image = $parse[count($parse)-1];
              $size = $parse[count($parse)-2];
  
              $value-&gt;setAttribute("src", '/?image='.$image."&amp;size=".$size);
          }
      }
  
      return $doc-&gt;saveHTML();
  }
  }
  </code></pre>
  
  <p>I spent several hours searching the web. Here is what I have tried so far:</p>
  
  <ul>
  <li><p><code>@$doc-&gt;loadHTML('&lt;?xml encoding="utf-8" ?&gt;'.$request-&gt;getData());</code></p></li>
  <li><p><code>libxml_use_internal_errors(true);
  $doc-&gt;loadHTML('&lt;?xml encoding="utf-8" ?&gt;'.$request-&gt;getData());</code></p></li>
  <li><p>I created a test.php file with this</p>
  
  <pre><code>&lt;?php
  $doc = new \DOMDocument('1.0');
  $doc-&gt;loadHTML('&lt;ul&gt;&lt;li&gt;text&lt;/li&gt;'.
  '&lt;li&gt;&amp;frac12; of this is &lt;strong&gt;strong&lt;/strong&lt;/li&gt;&lt;/ul&gt;');
  foreach ($doc-&gt;getElementsByTagName('li') as $node)
  {
      echo htmlentities(iconv('UTF-8', 'ISO-8859-1', $node-&gt;nodeValue)), "\n";
  }
  ?&gt;
  </code></pre>
  
  <p>which by the following command <code>php -f test.php &gt; res.html</code> occured in file res.html with <code>text</code> inside it.</p></li>
  <li><p>I also checked if <code>xml</code> module is loaded and it is.</p></li>
  </ul>
  
  <p>So, if I understand correct DOMDocument() thing workes in general, but not in the file in question. Why?</p>
  
  <p><strong>UPD</strong>. I'm not sure, but this seems like a reason for images not to be loaded properly.</p>