HTML文档中“< charset =” B”>的含义 [英] Meaning of `<meta charset="B">` in an HTML document

查看:75
本文介绍了HTML文档中“< charset =” B”>的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在学习HTML,与编码有关的一个方面使我感到困惑。



想象一下,我打开测试编辑器,编写一些HTML代码,并使用字符集 A 将其保存(例如UTF-8或ANSI或其他名称) )。然后,在我看来,会发生以下情况:


  1. 我键入的所有字符都映射到某些数字,该映射由charset A ;


  2. 数字以二进制形式表示为 0 s和 1 s。


在我刚刚保存的HTML文档中,有一行< meta charset = B> 其中, B 是与 A 不同的另一个字符集。



当我尝试使用浏览器打开HTML文档时会发生什么?它会根据字符集 B 将构成我的文档的 0 1 的序列映射到错误的字符(不是我指的是



如您所见,我试图理解的真实含义。 HTML文档中的meta charset = B>

解决方案

是的,完全正确地理解了。这正是 mojibake 的诞生方式;某些人试图使用错误的字符集来解释二进制序列,这可能导致显示意外/错误的字符,或者文档无法完整解码,这时的具体行为取决于尝试进行解码的应用程序。 / p>

<元字符集> 元素(实际上主要是 Content-Type HTTP标头)是建议,可通知客户端(浏览器)应使用哪种字符集来解释文档。否则,客户不知道。如果服务器/文档建议使用错误的字符集,则结果将在某种程度上被破坏。


I am learning HTML now, and one aspect related to the encoding confuses me.

Imagine, I open my test editor, write some HTML code and save it using charset A (e.g. UTF-8 or ANSI or something else). Then in my view the following happens:

  1. all characters I have typed are mapped to certain numbers, the mapping is specified by the charset A;

  2. the numbers are saved in the computer memory in their binary representation as sequences of 0 s and 1 s.

In the HTML document I have just saved there is a line <meta charset="B"> where B is another charset different from A.

What now happens when I attempt to open the HTML document with a browser? Will it map according to charset B the sequences of 0 s and 1 s which comprise my document to wrong characters (not the ones I meant when I wrote the document) and thus will display some rubbish?

As you see with this question I am trying to understand the real meaning of <meta charset="B"> in an HTML document.

解决方案

Yes, exactly, you have understood correctly. This is precisely how mojibake is being born; something is trying to interpret a binary sequence using the wrong character set, which either leads to unintended/wrong characters being displayed, or the document failing to decode entire, at which point the concrete behaviour depends on the application trying to do the decoding.

The <meta charset> element (and really primarily the Content-Type HTTP header) are advisory, informing the client (browser) in what character set it should interpret the document. Otherwise the client cannot know. If the server/document are advising the wrong charset, the result will be broken to some degree or another.

这篇关于HTML文档中“&lt; charset =” B”&gt;的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆