[PHP]Export CSV et UTF8

Salut,

Dans un back-office je dois exporter des listing clients en CSV, problème, j’ai des Grecs et là ça coince je n’arrive pas à avoir des caractères lisibles dans le csv.
Mes fichiers php sont en UTF-8, ma bdd d’où proviennent les listing aussi.

Voilà les headers que je balance dans le script :

header("Content-disposition: attachment; filename=export.csv"); header("Content-Type: application/force-download; charset=UTF-8"); header("Content-Transfer-Encoding: application/octet-stream\n"); header("Content-Length: ".filesize("export.csv")); header("Pragma: no-cache"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public"); header("Expires: 0"); readfile("export.csv");

Truc bizarre, je suis obligé d’ajouter un utf8_decode() sur les chaînes contenant des accents pour qu’ils s’affichent correctement… du genre

Normalement si tout est en UTF-8 ça ne devrait pas être le cas non ? Cela ne règle quand même pas mon problème de caractères helléniques.

Merci

Comment créé tu ton fichier “export.csv” ?

Dans la doc fopen de php, je lis que l’on peut définir le stream_encoding avec un contexte, as-tu bien créé ton fichier en UTF-8 ?
http://php.net/manual/fr/function.fopen.php
http://www.php.net/manual/fr/ref.stream.php

Même remarque pour ton readfile, tu ne l’as pas défini en UTF-8.

Oui mais stream_encoding n’existe pas sur ma version de php.

Résolu avec ça :

[code]if you have to write a file in UTF-8 format, you have to add an header to the file like this :

<?php $f=fopen("test.txt", "wb"); $text=utf8_encode("�a�!"); // adding header $text="\xEF\xBB\xBF".$text; fputs($f, $text); fclose($f); ?> [/code]

Le BOM doit spécifier l’encodage apparemment