'字符集=iso-8859-1'与 正在发出警告

发布于 2024-12-24 22:18:44 字数 758 浏览 6 评论 0 原文

我刚刚使用 W3C 验证器 验证了 HTML 文档,并发现如果我使用

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

: :

<!DOCTYPE HTML>
  • 它会抛出警告第 4 行,第 72 列:使用 windows-1252 而不是声明的编码 iso-8859-1。

但是,如果我使用:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

我真的不明白发生了什么事。另外,我什至不知道如何使用 DOCTYPE 标签,我只是从网络上复制并粘贴了一个标签。

  • 为什么会出现这种情况?
  • 我应该如何使用 DOCTYPE 标签?

I just validated an HTML document using the W3C validator, and found that if I use:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

with:

<!DOCTYPE HTML>
  • It throws a warning Line 4, Column 72: Using windows-1252 instead of the declared encoding iso-8859-1.

However, it is fixed if I use:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

I don't really understand what is happening. Also, I don't even know how to use the DOCTYPE tag, I just copied and pasted one from around the web.

  • Why does this happen?
  • How should I use the DOCTYPE tag?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

朱染 2024-12-31 22:18:44

更改 DOCTYPE 只是关闭警告 - 它实际上并没有解决任何问题。

iso-8859-1windows-1252 是非常相似的编码。它们的区别仅在于与从 0x80 到 0x9F 的 32 字节值关联的字符,这些字符在 iso-8859-1 中映射到控制字符,在 windows-1252 中映射到控制字符一些有用的字符,例如欧元符号。

控制字符在 HTML 中毫无用处,网络作者经常错误地声明 iso-8859-1,但却像使用 windows-1252 一样使用这 32 个值中的一个或多个值>,因此浏览器在看到声明的 iso-8859-1 字符集时会自动将其更改为 windows-1252

验证器只是警告您这种情况将会发生。如果您没有使用任何 32 字节值,那么您可以简单地忽略该警告 - 这不是错误。如果您确实想要字节值的 iso-8859-1 解释而不是 windows-1252 解释,那么您就做错了。

同样,这种切换发生在任何 DOCTYPE 的浏览器中,只是 HTML5 验证器比 HTML4 验证器更能帮助您了解它所告诉您的内容。

Changing the DOCTYPE is simply turning off the warning - it isn't actually fixing anything.

iso-8859-1 and windows-1252 are very similar encodings. They differ only in the characters associated with the 32 byte values from 0x80 to 0x9F, which in iso-8859-1 are mapped to control characters and in windows-1252 are mapped to some useful characters such as the Euro symbol.

The control characters are useless in HTML, and web authors often mistakenly declare iso-8859-1 and yet use one or more of those 32 values as if they were using windows-1252, so browsers when they see the iso-8859-1 charset being declared will automatically change this to be windows-1252.

The validator is simply warning you that this will happen. If you're not using any of the 32 byte values, then you can simply ignore the warning - it's not an error. If you are, and you genuinely want the iso-8859-1 interpretation of the byte values and not the windows-1252 interpretation, you are doing something wrong.

Again, this switching happens in browsers for any DOCTYPE, it's just that the HTML5 validator is being more helpful about what it is telling you than the HTML4 validator is.

回眸一遍 2024-12-31 22:18:44

有几点:

  1. 任何 HTML5 验证都应该持保留态度。该规范仍在积极开发中,并非一切都是一成不变的。
  2. 您正在为该元标记使用 HTML4 语法。尝试

也就是说,HTML 验证器在当今时代并没有多大作用。

但显然 HTML4 的默认值是 iso=8869-1。也就是说,HTML5 的默认字符集是 UTF-8。

有关 HTML5 文档类型的更多信息,请参阅 这篇文章 ://en.wikipedia.org/wiki/John_Resig" rel="nofollow noreferrer">约翰·雷西格。

A couple of points:

  1. Any HTML5 validation should be taken with a grain of salt. The specification is still under active development, and not everything is set in stone.
  2. You're using the HTML4 syntax for that meta tag. Try <meta charset="iso-8859-1">

That said, HTML validators don't serve that much purpose in this day and age.

But apparently the default for HTML4 was iso=8869-1. That said, the default charset for HTML5 is UTF-8.

More information about the HTML5 doctype can be found in this post by John Resig.

白鸥掠海 2024-12-31 22:18:44

它抛出警告第 4 行,第 72 列:使用 windows-1252 而不是声明的编码 iso-8859-1。

这意味着文件是使用编码 Windows-1252 创建时(也称为西方 Windows 1252 或 CP1252)和您的字符集声明说“嘿,使用 ISO 8859-1 读取此文件”,而这不是文件所具有的编码。

元字符集正是出于这个原因而存在。它的存在是为了声明您正在发送/读取/使用的文件的编码,因此当浏览器读取文档时,它知道该文件正在使用什么编码。

详细来说,您已声明此字符集:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

但您正在验证的文件实际上是用 Windows-1252 编码的。如何?为什么?检查您正在使用的文本编辑器以及它用于保存文件的编码。如果编辑器可以配置为更改编码,请选择您要使用的编码。

关于 HTML5

使用

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta charset="iso-8859-1">

都对 HTML5 有效。请参阅

It throws a warning Line 4, Column 72: Using windows-1252 instead of the declared encoding iso-8859-1.

It means the file was saved with the encoding Windows-1252 on creation (AKA Western Windows 1252 or CP1252) and your charset declaration says "hey read this file with ISO 8859-1" when that's not the encoding the file has.

The meta charset exist for that reason. It exist to declare the encoding of the file you are sending/reading/using so when, for example a browser, reads the document it knows what encoding the file is using.

In detail, you have this charset declared:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

But the file you are validating is actually encoded in Windows-1252. How? Why? Check the text editor you are using and what encoding it is using to save files. If the editor can be configured to change the encoding, choose the one you want to use.

About HTML5

Using

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

or

<meta charset="iso-8859-1">

are both valid for HTML5. See <meta charset="utf-8"> vs <meta http-equiv="Content-Type">

偏爱你一生 2024-12-31 22:18:44

W3C 验证器提供验证器使用的编码选项。您已在文档中指定编码,因此运行验证程序后,您应该在顶部信息块中看到“编码:iso-8859-1”。

在其右侧,有一个下拉菜单。将选项从“(自动检测)”更改为“iso-8859-1(西欧)”。然后验证器将使用 ISO 8859-1 而不是自己的选择,并且您不会收到该错误。

The W3C validator offers options for which encoding the validator uses. You have specified encoding in your document, so you should see "Encoding: iso-8859-1" in the top block of information once the validator has been run.

To the right of that, there is a pull-down menu. Change the choice from "(detect automatically)" to "iso-8859-1 (Western European)". The validator will then use ISO 8859-1 instead of its own choice, and you will not receive the error.

眉黛浅 2024-12-31 22:18:44

执行以下操作:

ISO 8859-15。是的,-15,它会起作用的。

Do the following:

ISO 8859-15. Yeah, -15, and it will work.

栀子花开つ 2024-12-31 22:18:44

不要在验证器上放置太多库存。通常有太多的 Internet Explorer 解决方法,特别是在 CSS 内容中,会出现问题验证器。如果您的页面可以在所有浏览器中运行并且您的客户满意,那么某些验证器说什么并不重要。

如果您指定 HTML5 文档类型,那么您应该与元字符集属性保持一致。为您的页面尝试一下:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
</head>

<body>
</body>
</html>

Don't place too much stock in the validators. There are typically too many Internet Explorer workarounds, particularly in the CSS content, that will trip up the validator. If your pages work in all browsers and your client is happy, it doesn't matter what some validator says.

If you are specifying the HTML5 doctype, then you should be consistent with the meta charset attribute. Try this though for your pages:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
</head>

<body>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文