PHP导出csv文件,在不同浏览器下,会出现乱码,firefox可以正常导出,chrome可能就出现乱码
解决的一个原则–统一编码
1、查看处理csv文件的代码所在的PHP文件是否为UTF8编码,ue查看是为‘U8-unix’;
2、代码实例
$newfilename=”out.csv”;
if(!file_exists($newfilename)) {
$fp=fopen(“$newfilename”, “w+”);
}
ob_end_clean();
header(“Content-Type: text/csv; charset=UTF-8”);
header(“Content-Disposition: attachment; filename=$newfilename”);
header(“Content-Encoding: binary”);
header(“Content-Length: “.filesize($newfilename));
header(“Pragma: no-cache”);
header(“Expires: 0”);
readfile($newfilename);
$e=ob_get_contents();
ob_end_clean();
echo $e;