我有一个关于在 Ubuntu 中使用 PHP 或 SHELL 将 UTF-8 转换为 CP1252 的问题。
背景:在 Ubuntu 中使用 PHP 或 SHELL 将 csv 文件从 UTF-8 转换为 CP1252,将文件从 Ubuntu 复制到 Windows,使用 nodepad++ 打开文件。
环境 :
- Ubuntu 10.04
- PHP 5.3
- 带有字母的文件 csv (œ, à, ç)
使用方法:
使用 PHP
iconv("UTF-8", "CP1252", "content of file")
或mb_convert_encoding("content of file", "UTF-8", "CP1252")
如果我检查生成的文件并file -i name_of_the_file
显示它:name_of_the_file: text/plain; charset=iso-8859-1
我将此转换后的文件复制到 windows 并用 notepad++ 打开,在右下角,我们可以看到编码是 ANSI
当我将编码从 ANSI 更改为 Windows- 1252,特殊字符显示良好。与 Shell
iconv -f UTF-8 -t CP1252" "content of file"
其余部分相同。
问题: 1. 为什么命令文件没有直接显示CP1252或ANSI,而是ISO-8895-1?2. 为什么我将编码从ANSI更改为Windows-1252时,特殊字符可以很好地显示。
先感谢您 !