title: Problem writing UTF-8 encoded file in PHP
body: <p>I have a large file that contains world countries/regions that I'm seperating into smaller files based on individual countries/regions. The original file contains entries like:</p>
  
  <pre><code>  EE.04 Järvamaa
    EE.05 Jõgevamaa
    EE.07 Läänemaa
  </code></pre>
  
  <p>However when I extract that and write it to a new file, the text becomes:</p>
  
  <pre><code>  EE.04  JÃ¤rvamaa
    EE.05  JÃµgevamaa
    EE.07  LÃ¤Ã¤nemaa
  </code></pre>
  
  <p>To save my files I'm using the following code:</p>
  
  <pre><code>mb_detect_encoding($text, "UTF-8") == "UTF-8" ? : $text = utf8_encode($text);
  $fp = fopen(MY_LOCATION,'wb');
  fwrite($fp,$text);
  fclose($fp);
  </code></pre>
  
  <p>I tried saving the files with and without utf8_encode() and neither seems to work. How would I go about saving the original encoding (which is UTF8)?</p>
  
  <p>Thank you!</p>