Can I declare two different charsets on one HTML p

2020-07-18 10:37发布

问题:

Is possible to specify two different character sets on a page using meta tags, like:

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">

I tried to add both of them and doesn't work :P

Thanks

回答1:

No, it's not possible. What would be the point of adding two different charset declarations? You should add only one declaration that matches your content.



回答2:

A "character set" is better referred to in this context as a "text encoding". Text is stored by computers as numbers. For a given piece of stored text, the encoding is the thing that defines which characters are represented by which numbers.

Because HTML is text, in order to display it, the browser needs to know what encoding the text is in. You therefore can't use two encodings in one HTML page, because one HTML page is one lump of text, and the declared encoding applies to all of it.

As @TomasMarkauskas has explained, the UTF-8 encoding can represent all characters that ISO-8859-1 can (and some characters than ISO-8859-1 can't). So you'll want to use UTF-8 for your HTML pages.