I've been at this one for a while. I'm trying to create a .csv file from a php script (that get the data from a database). My problem is that special characters are not displayed correctly.
Weird this is that the special characters that come from the database are shown correctly but he thing is I need to add certain characters to the entries.
For example, the database returns "Humidité" (French for humidity). That shows up correctly in the exported .csv.
But lets say I add a string to it from my php script
$member->humidity . ': 10% à 20%';
In the csv I will see
Humidité: 10% [weird characters] 20%
So the "é" from humidité is ok, but I don't see the "à" I added in PHP.
My headers seem ok, since some special characters are correctly displayed
$data = the whole csv file in a string
header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header("Content-Disposition: attachment; filename=file.csv");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header("Content-Length: " . strlen($data));
echo "\xEF\xBB\xBF"; // UTF-8 BOM
echo $data;
So my guess is that the problem comes from my Apache server.
When I found this I changed my default_charset = "utf-8" in my php.ini and added AddDefaultCharset UTF-8 in my httpd.conf bu that didn't solve it.
Any ideas? Thanks!