PHP 生成的 csv 文件显示 £ Excel 2007 中的英镑符号 (£)
我使用以下标头命令生成 csv 文件:
header("Content-type: text/csv; charset=utf-8; encoding=utf-8");
header('Content-Disposition: attachment; filename="products.csv"');
如果我在 Excel 2007 中打开该文件,则只要出现 £ 符号,我就会得到 £。但是,如果我在 Notepad++ 中打开该文件,则井号显示正常;同样,如果我将内容类型更改为文本/纯文本并删除附件标题,井号将在浏览器中正确显示。
一件奇怪的事情是,如果我进入 Notepad++ 中的“格式”菜单,则该文件似乎是用“UTF-8 without BOM”编码的。如果我将其更改为“以 UTF-8 编码”,然后保存文件,井号将在 Excel 中正确显示。有没有办法让PHP以这种编码保存文件?
I'm generating the csv file with the following header commands:
header("Content-type: text/csv; charset=utf-8; encoding=utf-8");
header('Content-Disposition: attachment; filename="products.csv"');
If I open the file in Excel 2007, then I get £ wherever a £ sign should appear. However, if I open the file in Notepad++, then the pound signs appear fine; similarly, if I change the content-type to text/plain and get rid of the attachement header, the pound signs appear correctly in the browser.
One strange thing is that if I go to the "Format" menu in Notepad++, it appears that the file is encoded in "UTF-8 without BOM". If I change this to "Encode in UTF-8", then save the file, the pound signs appear correctly in Excel. Is there a way to make it so that the file is saved in this encoding by PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在发出 CSV 数据之前输出
0xEF 0xBB 0xBF
。如果处理的话,不要忘记将内容长度标头增加 3。Output
0xEF 0xBB 0xBF
before emitting the CSV data. Don't forget to increase the content length header by 3 if you handle it.使用 utf8_decode() - 为我工作
Use utf8_decode() - WORKED FOR ME
上面由 user769889 发布,但我因对这个恼人的问题感到沮丧而错过了它,现在所有问题都已修复并正在工作。希望这对某人有帮助...
Posted as above by user769889 but I missed it with my frustrations with this v-annoying issue, all fixed now and working. Hope this helps someone...