htmlHow to set the character set: 1. Use "<meta charset="utf-8">"; 2. Pass "" method.
The operating environment of this article: windows7 system, HTML5&&CSS3 version, DELL G3 computer.
html 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 about the html file character set.
The first: the server specifies the character set of the response content;
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.
HTML video tutorial]
Solution If it is forwarding, you need to specify the character set of the returned data as utf-8 That’s it.response.setCharacterEncoding("utf-8");
##, 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!
Summary
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.
The above is the detailed content of How to set character set in html. For more information, please follow other related articles on the PHP Chinese website!