我正在生成csv文件,但它保存为“没有BOM的UTF-8”
如何保存为“带BOM的UTF-8”?
我在codeigniter中使用了以下标题
header('Content-Type: text/csv;charset=utf-8');
答案 0 :(得分:4)
这已经是How can I output a UTF-8 CSV in PHP that Excel will read properly?
的副本但是,您需要添加Byte Order Mark。这可以通过这种方式完成: https://stackoverflow.com/a/7601168/678611
<?php
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=<a filename>.csv');
header('Content-Transfer-Encoding: binary');
echo "\xEF\xBB\xBF"; // Byte Order Mark
echo $the_csv_file_content;
exit();
?>