title: How can I write a file in UTF-8 format?
body: <p>I have bunch of files that are not in UTF-8 encoding and I'm converting a site to UTF-8 encoding.</p>
  <p>I'm using simple script for files that I want to save in UTF-8, but the files are saved in old encoding:</p>
  <pre><code>header('Content-type: text/html; charset=utf-8');
  mb_internal_encoding('UTF-8');
  $fpath = &quot;folder&quot;;
  $d = dir($fpath);
  while (False !== ($a = $d-&gt;read()))
  {
      if ($a != '.' and $a != '..')
      {
          $npath = $fpath . '/' . $a;
  
          $data = file_get_contents($npath);
  
          file_put_contents('tempfolder/' . $a, $data);
      }
  }
  </code></pre>
  <p>How can I save files in UTF-8 encoding?</p>