How to export csv file, charset utf-8 instead of utf-8 without specification in php?

Possible duplicate:
String encoding as UTF-8 with specification in PHP

I can export csv file from php using this code

header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=data.csv'); $output = fopen('php://output', 'w'); 

but this code creates a file with charset utf-8 without BOM , but I need charset utf-8 .
way for this problem?

+4
source share
1 answer

Here is how I did it.

 header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); 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'); echo "\xEF\xBB\xBF"; // UTF-8 BOM echo $csv_file_content; exit(); 

Of course, you can replace echo $csv_file_content with what you need.

+14
source

All Articles