gpt4 book ai didi

encoding - Windows-1252 和 ISO-8859-1 之间的确切区别是什么?

转载 作者:行者123 更新时间:2023-12-02 18:50:37 37 4
gpt4 key购买 nike

我们在基于 Debian 的 LAMP 安装上托管 PHP 应用程序。一切都很好——性能、行政和管理方面。然而,作为新开发人员(我们还在高中),我们在西方字符集的字符编码方面遇到了一些问题。

经过大量研究,我得出的结论是网上的信息有些困惑。它谈论的是 Windows-1252 是 ANSI 且完全是 ISO-8859-1兼容。

无论如何,Windows-1252(1/3/4) 和 Windows-1252(1/3/4) 之间有什么区别ISO-8859-1?
无论如何,ANSI 是从哪里来的呢?

我们应该在 Debian 服务器(和工作站)上使用什么编码以确保客户获得预期的所有信息方式,并且我们不会在途中丢失任何字符?

最佳答案

我想以一种更像网络的方式来回答这个问题,为了回答这个问题,我们需要一些历史。 Joel Spolsky写了很good introductionary article每个开发人员都应该了解 Unicode 字符编码的最低限度知识。请耐心听我说,因为这将有点像 looong回答。 :)

作为历史,我将引用其中的一些引述:(非常感谢乔尔!:))

The only characters that mattered were good old unaccented English letters, and we had a code for them called ASCII which was able to represent every character using a number between 32 and 127. Space was 32, the letter "A" was 65, etc. This could conveniently be stored in 7 bits. Most computers in those days were using 8-bit bytes, so not only could you store every possible ASCII character, but you had a whole bit to spare, which, if you were wicked, you could use for your own devious purposes.

And all was good, assuming you were an English speaker. Because bytes have room for up to eight bits, lots of people got to thinking, "gosh, we can use the codes 128-255 for our own purposes." The trouble was, lots of people had this idea at the same time, and they had their own ideas of what should go where in the space from 128 to 255.

所以现在“OEM 字符集”随 PC 一起分发,但它们仍然不同且不兼容。令我们当代人惊讶的是——一切都很好!他们没有互联网,人们很少在不同区域设置的系统之间交换文件。

乔尔继续说道:

In fact as soon as people started buying PCs outside of America all kinds of different OEM character sets were dreamed up, which all used the top 128 characters for their own purposes. Eventually this OEM free-for-all got codified in the ANSI standard. In the ANSI standard, everybody agreed on what to do below 128, which was pretty much the same as ASCII, but there were lots of different ways to handle the characters from 128 and on up, depending on where you lived. These different systems were called code pages.

这就是“Windows 代码页”最终诞生的方式。它们实际上是 DOS 代码页的“父级”。然后Unicode诞生了! :) 和 UTF-8是“用于存储 Unicode 代码点字符串的另一个系统”,实际上“从 0-127 的每个代码点都存储在单个字节中”,与 ASCII 相同。 。我不会再详细讨论 Unicode 和 UTF-8,但您应该阅读 BOM , EndiannessCharacter Encoding作为一名将军。

关于“ANSI阴谋”,微软实际上承认Windows-1252的错误标签在 glossary of terms :

The so-called Windows character set (WinLatin1, or Windows code page 1252, to be exact) uses some of those positions for printable characters. Thus, the Windows character set is NOT identical with ISO 8859-1. The Windows character set is often called "ANSI character set", but this is SERIOUSLY MISLEADING. It has NOT been approved by ANSI.

因此,ANSI 在引用 Windows 字符集时并未经过 ANSI 认证! :)

正如 Jukka 所指出的(感谢您的出色回答)

Windows-1252 ISO Latin 1, also known as ISO-8859-1 as a character encoding, so that the code range 0x80 to 0x9F is reserved for control characters in ISO-8859-1 (so-called C1 Controls), wheres in Windows-1252, some of the codes there are assigned to printable characters (mostly punctuation characters), others are left undefined.

但是,我个人的观点和技术理解是,Windows-1252 和 ISO-8859-1 都不是网络编码! :) 所以:

  • 对于网页,请使用 UTF-8 作为内容编码因此,将数据存储为 UTF-8 并使用 HTTP Header“吐出” :Content-Type: text/html; charset=utf-8 .

    还有一种称为 HTML 内容类型元标记: <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    现在,浏览器在遇到此标记时实际执行的操作是再次从 HTML 文档的开头开始,以便可以按照声明的编码重新解释文档。仅当没有“Content-type” header 时才会发生这种情况。

  • 如果系统的用户需要从系统生成文件,请使用其他特定编码。例如,一些西方用户可能需要 Excel 生成的文件,或 Windows-1252 中的 CSV。如果是这种情况,请在该区域设置中编码文本,然后将其存储在文件系统上并将其作为可下载文件提供。

  • HTTP 设计中还有一件事需要注意:内容编码分发机制应该像这样工作。

    I. 客户端通过“Accept”和“Accept-Charset”request headers 请求特定内容类型和编码的网页。 .

    II.然后服务器(或 Web 应用程序)返回转码为该编码和字符集的内容。

大多数现代网络应用程序并非如此。 Web 应用程序以 UTF-8 形式提供(强制客户端)内容时实际发生了什么。这是有效的,因为浏览器根据响应 header 解释接收到的文档,而不是根据他们实际期望的内容。

我们都应该使用 Unicode,所以请尽可能使用 UTF-8 来分发您的内容,最重要的是适用。否则the elders of the Internet会困扰你! :)

附注可以找到一些有关在网页中使用 MS Windows 字符的更多精彩文章 herehere .

关于encoding - Windows-1252 和 ISO-8859-1 之间的确切区别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19109899/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com