gpt4 book ai didi

php - 通过 PHP 为 utf-8 字符导出 CSV

转载 作者:搜寻专家 更新时间:2023-10-31 21:15:13 24 4
gpt4 key购买 nike

我需要用 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 打开导出的文件时,显示了错误的字符。当我用记事本打开文件时,字符显示正确。我该如何解决这个问题?

最佳答案

这是我的做法。

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";

之前我得到的是垃圾字符,现在导出了正确的数据。

关于php - 通过 PHP 为 utf-8 字符导出 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10361492/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com