本文介绍了PHP:将UTF-8字符串转换为Ansi?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从数据库中的值构建了一个csv字符串.最终的字符串存储在我的$ csv变量中.

I build a csv string from values I have in my DB. The final string is stored in my $csv variable.

现在,我提供此字符串供下载,如下所示:

Now I offer this string for download, like this:

header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=whatever.csv");
header("Pragma: no-cache");
header("Expires: 0");

echo $csv;

例如,当我在Notepad ++中打开它时,它说 Ansi为UTF-8 .我该如何仅将其更改为Ansi?

When I open this in Notepad++ for example, it says Ansi as UTF-8. How can I chnage that to Ansi only?

我尝试过:

$csv = iconv("ISO-8859-1", "WINDOWS-1252", $csv);

那并没有改变任何东西.

That did not change anything.

谢谢!

解决方案: $ csv = iconv("UTF-8","WINDOWS-1252",$ csv);

Solution: $csv = iconv("UTF-8", "WINDOWS-1252", $csv);

推荐答案

尝试:

$csv = iconv("UTF-8", "Windows-1252", $csv);

但是您最终将丢失数据,因为ANSI只能对UTF-8的一小部分进行编码.如果您没有很强的理由反对,请以UTF-8编码格式提供文件.

But you will eventually lose data because ANSI can only encode a small subset of UTF-8. If you don't have a very strong reason against it, serve your files UTF-8 encoded.

这篇关于PHP:将UTF-8字符串转换为Ansi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 16:56