Methods to set the html character set: 1. Through the "<meta charset="utf-8">" method; 2. Through the "" method.
The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.
How to set the html character set
Two ways to specify the page character set
Method 1:
<meta charset="utf-8">
Method 2:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
The above are two ways to set the character set of the page to UTF-8 (setting the page character set). The purpose is to tell the browser that The character set of the html file.
Two ways to set the character set used by the page
First: The server specifies the response content Character set;
response.setCharacterEncoding("utf-8")
Premise: The server forwards or redirects to the specified interface through the server.
Second type: page-specified character set.
See 1
Note: The first method has higher priority than the second method.
Server forwarding
Cause analysis
Solution
response.setCharacterEncoding("utf-8");
Server redirection
If the page is redirected and the encoding set of the returned data is not specified, what will happen to the page? The character set is determined by the page, that is, the character set of the page is determined by the statement about the character set on the page. For example: if the character set specified on the page is: iso-8859-1##, then the browser will parse it according to iso-8859-1.
In addition, even if the redirection sets the encoding set of the returned data, it will be invalid because: redirection will cause data loss!
5. SummaryIf the page is forwarded by the server, the character set of the page is determined by the forwarding; otherwise, the character set of the redirected interface or the normal interface Determined by the declared character set of the HTML page itself!
Note: Today we are talking about the page character set problem and the garbled characters that appear during pure data interaction are not the same thing!
In addition, if the character set is specified in both the HTTP response header and meta, a conflict will occur, and the character set of the http response will take effect.
[Recommended learning:
css video tutorialThe above is the detailed content of How to set html character set. For more information, please follow other related articles on the PHP Chinese website!