"; 2. Pass "" mode setting."/> "; 2. Pass "" mode setting.">

Home >Web Front-end >Front-end Q&A >How to set character set in html

How to set character set in html

藏色散人
藏色散人Original
2021-04-28 09:35:074317browse

htmlHow to set the character set: 1. Use "09477266eebbc8a01f42387ae29e71dd"; 2. Pass "679669730644ab6dc84f22ee9afa4251" method.

How to set character set in html

The operating environment of this article: windows7 system, HTML5&&CSS3 version, DELL G3 computer.

html Two ways to specify the page character set

  • htmlTwo 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.

  • Two ways to set the character set used by the page

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.

  • Server forwarding

## The page has set the character set

What’s going on? Why doesn’t it take effect?

2. Cause analysis

Complete the page jump request (forwarding) through the server

When returning, the destination is not specified. Returns the character set of the data.

 f12 captures the network, and the character set of the corresponding page obtained is iso-8859-1, so garbled characters will appear when the browser parses the page.

[Recommended learning:

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");

4. 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!

Summary

If 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 is determined by the declared characters of the HTML page itself Set decision!

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn