windows 字符编码,UTF 还是 ANSI?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2631870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Character Encoding, UTF or ANSI?
提问by Paulo Coghi - Reinstate Monica
I'm using Eclipse in Ubuntu to edit PHP files.
我在 Ubuntu 中使用 Eclipse 来编辑 PHP 文件。
But, unfortunately, some of these PHP files were created in Notepad++ in Windows XP, with ANSI encoding defined.
但是,不幸的是,其中一些 PHP 文件是在 Windows XP 的 Notepad++ 中创建的,并定义了 ANSI 编码。
Also, these files generates HTML codes with charset=ISO-8859-1.
此外,这些文件会生成带有 charset=ISO-8859-1 的 HTML 代码。
When I configured Eclipse to ISO-8859-1, many special characters were lost and changed to '???', and when I try to save a file with ISO enconding, Eclipse displays an error that was not possible to save the file because some characters aren't compatible with the charset.
当我将 Eclipse 配置为 ISO-8859-1 时,许多特殊字符丢失并更改为“???”,并且当我尝试使用 ISO 编码保存文件时,Eclipse 显示无法保存文件的错误,因为某些字符与字符集不兼容。
How can I save these files without changing the encoding, or how can I change the encoding without lose characters.
如何在不更改编码的情况下保存这些文件,或者如何在不丢失字符的情况下更改编码。
回答by BalusC
To the point, you need to readthose files using ANSI
encoding and then writethose files using ISO-8859-1
encoding. In Notepad++ you can change the encoding by Formatmenu option. Unfortunately there's no ISO-8859-1
option, but UTF-8
should suffice and is nowadays also the preferred choice for world domination since the ISO-8859-1
encoding only covers latin characters, not for example Cyrillic, Greek, Chinese, Arabic, etcetera.
就此而言,您需要使用编码读取这些文件ANSI
,然后使用编码写入这些文件ISO-8859-1
。在 Notepad++ 中,您可以通过格式菜单选项更改编码。不幸的是,没有ISO-8859-1
选择,但UTF-8
应该足够了,而且现在也是统治世界的首选,因为ISO-8859-1
编码只涵盖拉丁字符,而不是例如西里尔文、希腊文、中文、阿拉伯文等。
回答by Ignacio Vazquez-Abrams
By "ANSI" do you mean "Windows code page 1252"?
“ANSI”是指“Windows 代码页 1252”吗?
In either case, once you figure out the source encoding you can use iconv
to convert from that encoding to UTF-8.
无论哪种情况,一旦您确定了源编码,您就可以iconv
将其从该编码转换为 UTF-8。
回答by MikeyKennethR
The latest version can CONVERT between ISO-8859-1 and UTF-8 without loosing info. version 5.6.8 is able to do so.
最新版本可以在 ISO-8859-1 和 UTF-8 之间转换而不会丢失信息。版本 5.6.8 能够这样做。