CSV 变音符号未正确解析

CSV diacritic characters not parsed correclty

我在导出 CSV 时遇到问题。

headers 看起来像这样:

header('Content-Encoding: unicode');
header('Content-type: text/csv; charset=unicode');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="'.$fname.'.csv"');
header("Content-length: 21474836470"); // tells file size set it to maximum    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //Must revalidate
header('Pragma: no-cache');
header('Expires: 0');

数据打印正确,但在 CSV 格式中出现混乱 我尝试将 Content-Encoding 更改为 utf-8、iso-8859-1 等。

  1. Content-Encoding 不表示 character 编码,它表示 transport 编码。例如,如果 HTTP 响应被压缩,它会显示 gzip
  2. unicode 不是一种编码,它是一种定义标准。 UTF-8ISO-5589-1等是具体的编码。
  3. 这在很大程度上取决于您使用哪个应用程序打开生成的文件。应该是 Excel 我会让你知道它在编码方面出了名的糟糕。在 SO 上搜索关于 Excel 和 CSV 编码的许多问题,例如 How can I output a UTF-8 CSV in PHP that Excel will read properly?。否则,我们将需要更多信息才能发表意见。