Html 元字符集 windows-1252 与 UTF-8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16448409/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:12:43  来源:igfitidea点击:

meta charset windows-1252 vs UTF-8

htmlcharacter-encodingfontsmeta-tags

提问by Joe

My HTML pages use <meta charset="windows-1252">.

我的 HTML 页面使用<meta charset="windows-1252">.

  1. Is changing to UTF-8recommended and why?
  2. I checked some of my pages with UTF-8and got question marks with some math symbols. E.G: x should be changed to × in order to show correctly. I tried the CpConverterbut it did not convert well all the symbols.
  1. 是否改为UTF-8推荐,为什么?
  2. 我检查了我的一些页面UTF-8并得到了一些数学符号的问号。EG: x 应该改为 × 才能正确显示。我试过了,CpConverter但它没有很好地转换所有符号。

Is there a better way to convert many files?

有没有更好的方法来转换许多文件?

回答by Mateusz

  1. UTF-8is generally approved standard, which works everywhere. Windows-any encoding is Windows-specific and not guaranteed to work on any machine. Also, take a look hereand here
  2. If you want to change the encoding of a file, you can do it in many ways. You can look for encoding type in your text editor/IDE or use the following command (not tested, it should work though):
  1. UTF-8是普遍认可的标准,适用于任何地方。Windows-any 编码是特定于 Windows 的,不能保证在任何机器上都能工作。另外,看看这里这里
  2. 如果要更改文件的编码,可以通过多种方式进行。您可以在文本编辑器/IDE 中查找编码类型或使用以下命令(未测试,但它应该可以工作):

iconv -f WINDOWS-1252 -t UTF-8 filename.txt

iconv -f WINDOWS-1252 -t UTF-8 filename.txt

回答by desmati

It's an old question but my answer may help someone to decide better.

这是一个老问题,但我的回答可能会帮助某人做出更好的决定。

Changing from ANSI(windows-1252) to UTF-8 approximately doubles the size of HTML files. (Depending on characters used in the file)

从 ANSI(windows-1252) 更改为 UTF-8 大约会使 HTML 文件的大小增加一倍。(取决于文件中使用的字符)

If you want to test this, just create a file in notepad with the following characters:

如果要对此进行测试,只需在记事本中创建一个包含以下字符的文件:

???

???

These characters are both in ANSI(Windows-1256) and Unicode. Save the file once with ANSI(Windows-1256) encoding and once again with UTF-8 encoding.

这些字符都是 ANSI(Windows-1256) 和 Unicode。使用 ANSI(Windows-1256) 编码保存文件一次,再使用 UTF-8 编码保存文件。

Size of the UTF-8 file: 9 bytes

UTF-8 文件的大小:9 字节

Size of the ANSI(Windows-1256) file: 3 bytes

ANSI(Windows-1256) 文件的大小:3 字节

if you want to change the charset of your page, simply open them in notepad or any other editor and save as with UTF-8 encoding.

如果您想更改页面的字符集,只需在记事本或任何其他编辑器中打开它们并使用 UTF-8 编码另存为。