3

我需要用 php 导出一个 .csv 文件。我使用下面的代码来做到这一点:

header('Content-Encoding: UTF-8');
header('Content-type: application/csv; charset=UTF-8');
header("Content-Disposition: attachment; filename=$fn");
echo "\xEF\xBB\xBF"; // UTF-8 BOM
print($csv); 

$csv包含一些波斯字符。当我用 ms excel 打开导出的文件时,显示错误的字符。当我打开带有记事本字符的文件时,显示正确。我怎么解决这个问题?

4

1 回答 1

2

这就是我的做法。

header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
header('Content-Transfer-Encoding: binary');
echo "\xEF\xBB\xBF";

早些时候我得到了垃圾字符,现在导出了正确的数据。

于 2014-04-29T10:55:03.280 回答