Outputting file contents as UTF-8 leads to character encoding issues <p>I set my header as follows:</p> <pre><code>header( 'Content-Type: text/html; charset="utf-8"' ); </code></pre> <p>and then output a local file on my server to the browser using the following code-segment:</p> <pre><code>$content = file_get_contents($sPath); $content = mb_convert_encoding($content, 'UTF-8'); echo $content; </code></pre> <p>The files I have on the server are created by lua and thus, the output of the following is <code>FALSE</code> (before conversion):</p> <pre><code>var_dump( mb_detect_encoding($content) ); </code></pre> <p>The files contain some characters like <code>™</code> (<code>&amp;trade;</code>) etc. and these appear as plain square boxes in browsers. I've read the following threads which were suggested as similar questions and none of the variations in my code helped:</p> <ul> <li><a href="http://stackoverflow.com/q/17709888/1190388">PHP File Get Contents &amp; String Encoding</a> (No gzip in my case, the files are plain <code>.txt</code>s)</li> <li><a href="http://stackoverflow.com/q/2236668/1190388">file_get_contents() Breaks Up UTF-8 Characters</a> (Tried first two top-rated solutions, neither worked. The third one isn't applicable for my case)</li> <li><a href="http://stackoverflow.com/q/5600371/1190388">file_get_contents() converts UTF-8 to ISO-8859-1</a> (No stream is there to provide as context)</li> </ul> <p>There seem to be no problems when I simply use the following:</p> <pre><code>header( 'Content-Type: text/html; charset="iso-8859-1"' ); // setting path here $content = file_get_contents($sPath); echo $content; </code></pre>