title: Is there a way to keep entities intact while parsing html with DomDocument?
body: <p>I have this function to ensure every <strong>img</strong> tag has absolute URL:</p>
  
  <pre><code>function absoluteSrc($html, $encoding = 'utf-8')
  {
      $dom = new DOMDocument();
      // Workaround to use proper encoding
      $prehtml  = "&lt;html&gt;&lt;head&gt;&lt;meta http-equiv=\"Content-Type\" content=\"text/html; charset={$encoding}\"&gt;&lt;/head&gt;&lt;body&gt;";
      $posthtml = "&lt;/body&gt;&lt;/html&gt;";
  
      if($dom-&gt;loadHTML( $prehtml . trim($html) . $posthtml)){
          foreach($dom-&gt;getElementsByTagName('img') as $img){
              if($img instanceof DOMElement){
                  $src = $img-&gt;getAttribute('src');
                  if( strpos($src, 'http://') !== 0 ){
                      $img-&gt;setAttribute('src', 'http://my.server/' . $src);
                  }
              }
          }
  
          $html = $dom-&gt;saveHTML();
  
          // Remove remains of workaround / DomDocument additions
          $cut_start  = strpos($html, '&lt;body&gt;') + 6;
          $cut_length = -1 * (1+strlen($posthtml));
          $html = substr($html, $cut_start, $cut_length);
      }
      return $html;
  }
  </code></pre>
  
  <p>It works fine, but it returns decoded entities as unicode characters</p>
  
  <pre><code>$html = &lt;&lt;&lt; EOHTML
  &lt;p&gt;&lt;img src="images/lorem.jpg" alt="lorem" align="left"&gt;
  Lorem ipsum dolor sit amet consectetuer Nullam felis laoreet
  Cum magna. Suscipit sed vel tincidunt urna.&lt;br&gt;
  Vel consequat pretium Curabitur faucibus justo adipiscing elit.
  &lt;img src="others/ipsum.png" alt="ipsum" align="right"&gt;&lt;/p&gt;
  
  &lt;center&gt;&amp;copy; Dr&amp;nbsp;Jekyll &amp;#38; Mr&amp;nbsp;Hyde&lt;/center&gt;
  EOHTML;
  
  echo absoluteSrc($html);
  </code></pre>
  
  <p>Outputs: </p>
  
  <pre><code>&lt;p&gt;&lt;img src="http://my.server/images/lorem.jpg" alt="lorem" align="left"&gt;
  Lorem ipsum dolor sit amet consectetuer Nullam felis laoreet
  Cum magna. Suscipit sed vel tincidunt urna.&lt;br&gt;
  Vel consequat pretium Curabitur faucibus justo adipiscing elit.
  &lt;img src="http://my.server/others/ipsum.png" alt="ipsum" align="right"&gt;&lt;/p&gt;
  
  &lt;center&gt;© Dr Jekyll &amp;amp; Mr Hyde&lt;/center&gt;
  </code></pre>
  
  <p>As you can see in the last line</p>
  
  <ul>
  <li><strong>&amp;copy;</strong> is translated to <strong>©</strong> (U+00A9), </li>
  <li><strong>&amp;nbsp;</strong> to non-breaking space (U+00A0),</li>
  <li><strong>&amp;#38;</strong> to <strong>&amp;amp;</strong></li>
  </ul>
  
  <p>I would like them to remain the same as in input string.</p>