PHP生成的csv文件在Excel 2007中显示英镑英镑符号(£) [英] PHP generated csv file is displaying £ for a UK pound sign (£) in Excel 2007

查看:543
本文介绍了PHP生成的csv文件在Excel 2007中显示英镑英镑符号(£)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下标头命令生成csv文件:

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

如果我在Excel 2007中打开文件,但是,如果我在记事本++中打开文件,那么磅的迹象看起来很好;类似地,如果我将内容类型改为text / plain并摆脱附件头,那么井号就会在浏览器中正确显示。

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.

一个奇怪的事情是如果我去Notepad ++中的格式菜单,似乎该文件被编码在UTF-8没有BOM。如果我将其更改为UTF-8编码,然后保存文件,英镑符号在Excel中正确显示。有没有办法让文件通过PHP保存在这个编码中?

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?

推荐答案

输出 0xEF 0xBB 0xBF ,然后发出CSV数据。

Output 0xEF 0xBB 0xBF before emitting the CSV data. Don't forget to increase the content length header by 3 if you handle it.

header('Content-type: text/csv;');
header('Content-Length: ' + strlen($content) + 3);
header('Content-disposition: attachment;filename=UK_order_' . date('Ymdhis') . '.csv');
echo "\xef\xbb\xbf";
echo $content;
exit;

这篇关于PHP生成的csv文件在Excel 2007中显示英镑英镑符号(£)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆