如何保存为"UTF-8 with BOM"编码?



我正在生成csv文件,但它保存为"UTF-8 without BOM"

如何保存为"UTF-8 with BOM"?

我使用以下头在codeigniter

 header('Content-Type: text/csv;charset=utf-8');

这已经是一个副本,我如何在PHP中输出一个UTF-8 CSV, Excel将正确读取?

但是你需要包含一个字节顺序标记。可以这样做: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 "xEFxBBxBF"; // Byte Order Mark
echo $the_csv_file_content;
exit();
?>

最新更新