title: DOMDocument encoding problems / characters transformed
body: <p>I am using DOMDocument to manipulate / modify HTML before it gets output to the page. This is only a html fragment, not a complete page. My initial problem was that all french character got messed up, which I was able to correct after some trial-and-error. Now, it seems only one problem remains : ' character gets transformed into ? .</p>
  
  <p>The code : </p>
  
  <pre><code>&lt;?php
      $dom = new DOMDocument('1.0','utf-8');
           $dom-&gt;loadHTML(utf8_decode($row-&gt;text));
  
           //Some pretty basic modification here, not even related to text
  
           //reinsert HTML, and make sure to remove DOCTYPE, html and body that get added auto.
           $row-&gt;text = utf8_encode(preg_replace('/^&lt;!DOCTYPE.+?&gt;/', '', str_replace( array('&lt;html&gt;', '&lt;/html&gt;', '&lt;body&gt;', '&lt;/body&gt;'), array('', '', '', ''), $dom-&gt;saveHTML())));
  ?&gt;
  </code></pre>
  
  <p>I know it's getting messy with the utf8 decode/encode, but this is the only way I could make it work so far. Here is a sample string :</p>
  
  <p>Input :
  Sans doute parce qu’il vient d’atteindre une date déterminante dans son spectaculaire cheminement</p>
  
  <p>Output :
  Sans doute parce qu?il vient d?atteindre une date d&eacute;terminante dans son spectaculaire cheminement</p>
  
  <p>If I find any more details, I'll add them. Thank you for your time and support!</p>