UTF-8 characters in fwrite
<p>I'm trying to save HTML to a .html file, </p>

<p>This is working:</p>

<pre><code>$html_file = "output.html";
$output_string="string with characters like ã or ì";
$fileHandle = fopen($html_file, 'w') or die("file could not be accessed/created");
fwrite($fileHandle, $output_string);
fclose($fileHandle);
</code></pre>

<p>When I check the output.html file, these special characters in my output_string are not read correctly.</p>

<p>My HTML file <strong>can't</strong> have a <code>&lt;head&gt;</code> tag with the charset information, this makes it work, but my output can't have any <code>&lt;html&gt;</code>, <code>&lt;head&gt;</code> or <code>&lt;body&gt;</code> tags.</p>

<p>I have tried stuff like </p>

<pre><code>header('Content-type: text/plain; charset=utf-8');
</code></pre>

<p>I also tried <strong>utf8_encode()</strong> on the string before fwrite, but with no success so far. </p>

<p>If I read the output.html file in Notepad++ or Netbeans IDE, it shows the correct characters being saved, it's the browser that isn't them reading properly.</p>

<p>I'm pretty sure PHP is saving my file with the incorrect charset, because if I create HTML files in my computer with those special characters (even without any  charset setting), these are read correctly.</p>
