I'm trying to create a CSV file using php. How can I print non ascii characters?
It is possible to use unicode characters in CSV-files, just make sure you use the right HTTP-headers. This works great in OpenOffice, but if I remember right Excel has some problems displaying CSV-files with unicode characters.
Furthermore you should try to use fputcsv, it makes things easier. When you are creating files on the fly, you can use the php output stream.
So something like this:
$handle = fopen("php://output", "w");
header("Content-Type: text/csv; charset=UTF-8");
fputcsv($handle, $fields, ';', '"');
fclose($handle);
EDIT
After reading your comments it seems you have problems converting htmlentities like é
. To convert these entities you have to make sure every field is decoded. You can do this with html_entity_decode like this:
$decoded_string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
Btw, most of the time it's not a good idea to store text with htmlentities in a database, because when you don't want to output html (like in this case) you have to convert them back to real characters. It's easier to just store the text as unicode.