title: PHP CSV encoding not utf-8
body: <p>I am generating a CSV file with PHP and saving it on the hard disk (I do not want a download). The database charset is <code>utf8_general_ci</code> and there are chars in there like the degrees sign (<code>°</code>), which show up perfectly in PHPmyadmin. These chars need to be saved in the CSV file. Everything I do is in UTF-8, but the file gets saved with the encoding <code>ISO-8859-1</code>. If I start using the <code>utf8_encode</code> function, other chars show up (<code>Â</code>) when I convert it back to <code>UTF-8</code> in excel or any other text editor. I do not know what is going wrong and I have spent hours to track it down, without success.</p>
  
  <p>I have tried <code>SET NAMES utf8</code> just to be sure it is <code>UTF-8</code>, but that just causes more strange characters and no <code>UTF-8</code> encoding. Using MySQLi's <code>set_charset</code> does the same. With the header as <code>Content-type:text/html;charset=UTF-8</code> the CSV still does not have utf-8 as default encoding, nor with any of these combinations.</p>
  
  <p>Some code:</p>
  
  <pre><code>header("Content-type:text/html;charset=UTF-8");
  $rMysqli = new mysqli("localhost", "user", "pass", "database");
  $rCSV = fopen("test_".time().".csv", 'w');
  
  $aCSVdata = array($var1, $var2, $var3);
  fputcsv($rCSV, $aCSVdata, ",", "\"");
  
  fclose($rCSV);
  </code></pre>
  
  <p>That is pretty much all is happening. Just normal CSV data, only with special chars such as <code>°</code> and <code>Ø</code>. </p>