title: How to set text file encoding in PHP?
body: <p>How can I set a text file ENCODING (for instance UTF-8) in PHP?</p>
  
  <p>Let me show you my problem. This is my code:</p>
  
  <pre><code>&lt;?php 
  file_put_contents('test.txt', $data); // data is some non-English text with UTF-8 charset
  ?&gt;
  </code></pre>
  
  <p>Output: <code>Ø§Ù</code>!</p>
  
  <p><code>fwrite()</code> has the similar output.</p>
  
  <p>But when I create the <code>test.txt</code> by notepad and set the charset <strong>UTF-8</strong> the output is what I want.
  I wanna set the charset in the PHP file.</p>
  
  <p>Now this is my question: How to set text file encoding by PHP?</p>