188.md 1.6 KB
Newer Older
W
wizardforcel 已提交
1
# HTML5 字符集 – 字符编码声明
W
wizardforcel 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

> 原文: [https://howtodoinjava.com/html5/html5-charset/](https://howtodoinjava.com/html5/html5-charset/)

如今,针对不同地理位置和语言以及不同语言的 Web 主机应用程序使用不同的字符集或字符集。 要通知浏览器 HTML5 文档中使用的字符集,您需要使用**元**标签,并将其命名为`charset`

我们来看`UTF-8``charset`声明的示例。

```java
<meta charset = "UTF-8" />
```

I would recommend using UTF-8 wherever possible, since it can represent any character in almost 99.99% cases. It is also well supported by most of the modern browsers.

如果要使用旧方式提供**字符集**信息,则将使用以下格式。 在此提供此信息仅供参考,不建议使用。

```java
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

```

XHTML 文档具有第三种选择:通过 XML 声明来表示字符编码:

```java
<?xml version="1.0" encoding="UTF-8"?>

```

1.  尽管`UTF-8`在大多​​数情况下都可以使用,但是许多开发人员发现使用`ISO-8859-1`作为字符集可以提供更大的灵活性。
2.  另一个字符集`UTF-16`有时会导致错误的字符,并且在某些情况下会导致应用程序无法正常运行。
3.  大多数现代的网络浏览器都具有自动字符编码检测功能(如果未明确声明)。

学习愉快!

参考:
[https://www.w3.org/International/articles/http-charset/index](https://www.w3.org/International/articles/http-charset/index)
[https://en.wikipedia.org/wiki/Character_encodings_in_HTML](https://en.wikipedia.org/wiki/Character_encodings_in_HTML)