title: utf-8 encoding in DOMDocument class
body: <p>I am using PHP's DOMDocument class to open an HTML file, make some changes, and save it. The problem is that the javascript in every page that is loaded, contains utf 8 characters, and when I save the HTML file, these characters are "changed". Here's my code.</p>
  
  <pre><code>$doc=new DOMDocument();
  $doc-&gt;loadHTMLFile($path);
  
  $doc-&gt;encoding='UTF-8';
  $doc-&gt;saveHTMLFile($path);
  </code></pre>
  
  <p>The file is saved again but the special characters gets distorted. e.g if my javascript had an image path set to <code>french/Comment ça s’écrit/</code> , this becomes <code>french/Comment&amp;ensp;&amp;ccedil;a&amp;ensp;s&amp;rsquo;&amp;eacute;crit&amp;ensp;</code> . The wierd thing is that this only happens to my javascript paths, the html elements dont get changed and are in the correct encoding.</p>