Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Mar 222011
 

Sending a UTF8 encoded CSV from PHP

Answer:

It is easy to generate a CSV file using the fputcsv function. One of a very common problems is even the file is UTF-8 encoded, Microsoft Excel is still unable to identiy the file as UTF-8.

To solve this, you need to add the UTF-8 BOM to the beginning of the file.

E.g.

<?php 

echo "\xEF\xBB\xBF" . $csvdata; // Assume $csvdata contains the CSV string you want to output

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>