UTF-8和ISO-8859-1有什么区别?
当前回答
ISO-8859-1 is a legacy standards from back in 1980s. It can only represent 256 characters so only suitable for some languages in western world. Even for many supported languages, some characters are missing. If you create a text file in this encoding and try copy/paste some Chinese characters, you will see weird results. So in other words, don't use it. Unicode has taken over the world and UTF-8 is pretty much the standards these days unless you have some legacy reasons (like HTTP headers which needs to compatible with everything).
其他回答
UTF-8是一种多字节编码,可以表示任何Unicode字符。ISO 8859-1是一种单字节编码,可以表示Unicode的前256个字符。两者都以完全相同的方式编码ASCII。
维基百科解释得很好:UTF-8 vs Latin-1 (ISO-8859-1)。前者为变长编码,后者为单字节定长编码。 Latin-1只编码Unicode字符集的前256个码位,而UTF-8可用于编码所有码位。在物理编码级别,只有码点0 - 127编码相同;编码点128 - 255的不同之处在于,使用UTF-8时会变成2字节序列,而使用Latin-1时会变成单字节序列。
从另一个角度来看,unicode和ascii编码都无法读取的文件,因为其中有一个字节0xc0,似乎可以被iso-8859-1正确读取。需要注意的是,文件中当然不应该包含unicode字符。
ASCII: 7位。128码位。 iso -8859- 1:8位。256个码位。 UTF-8: 8-32位(1-4字节)。1,112,064个代码点。
ISO-8859-1和UTF-8都与ASCII向后兼容,但UTF-8与ISO-8859-1不向后兼容:
#!/usr/bin/env python3
c = chr(0xa9)
print(c)
print(c.encode('utf-8'))
print(c.encode('iso-8859-1'))
输出:
©
b'\xc2\xa9'
b'\xa9'
ISO-8859-1 is a legacy standards from back in 1980s. It can only represent 256 characters so only suitable for some languages in western world. Even for many supported languages, some characters are missing. If you create a text file in this encoding and try copy/paste some Chinese characters, you will see weird results. So in other words, don't use it. Unicode has taken over the world and UTF-8 is pretty much the standards these days unless you have some legacy reasons (like HTTP headers which needs to compatible with everything).
推荐文章
- 将Unicode文本写入文本文件?
- PHP DOMDocument loadHTML没有正确编码UTF-8
- 什么是ANSI格式?
- 如何在Bash中回显4位Unicode字符?
- UTF-8字节[]到字符串
- 什么是垂直标签?
- Python字符串中的u'\ufeff'
- 如何转换字符串和从UTF8字节数组在Java
- 如何在资源包的资源属性中使用UTF-8
- utf - 8:将军?本吗?Unicode吗?
- 如何检查字符串是否为unicode或ascii?
- “不正确的字符串值”时,试图插入UTF-8到MySQL通过JDBC?
- 有一个上下颠倒的插入符号吗?
- 检测编码并使所有内容都为UTF-8
- 'utf-8' codec不能解码字节0xff在位置0:无效的开始字节