Php encoding. I. Page encoding 1. use METAhttp-equivcontent-typecontenttexthtml; the charsetxxx tag sets the page encoding tag to declare the character set used by the client browser. I. Page encoding
1. use Tag settings page encoding
The role of this label is to declare the client browser with what character set encoding to display the page, xxx can be GB2312, GBK, UTF-8 (and MySQL is UTF8) and so on. Therefore, most pages can use this method to tell the browser what encoding is used to display the page, so as not to cause code errors and generate garbage codes. However, sometimes we will find that this sentence still does not work. no matter which type of xxx is, the browser always uses an encoding. I will talk about this later.
Please note that, Html information is only a declaration. it indicates that the server has passed HTML information to the browser.
2. header ("content-type: text/html; charset = xxx ");
This function header () sends the information in the brackets to the http header.
If the content in the brackets is as described in this article, the function and The tags are basically the same. you can check the first one and find that all the characters are similar. But the difference is that if there is this function, the browser will always use the xxx code you requested, and it will never be disobedient, so this function is very useful. Why? Let's talk about the differences between the HTTPS header and the HTML information:
The https header is the string sent by the server before the server sends HTML information to the browser over HTTP.
Because meta tags belong to html information, the content sent by header () first arrives in the browser. the common point is that header () has a higher priority than meta (I don't know if I can do this ). Add a php page with both header ("content-type: text/html; charset = xxx") and The browser only recognizes the http header instead of the meta. Of course, this function can only be used on the php page.
There is also a problem. why is the former absolutely effective, while the latter sometimes does not? This is the reason for Apache.
The conf folder in the Apache root directory contains the entire Apache configuration file httpd. conf.
Open httpd. conf in a text editor. line 1 (different versions may be different) has adddefacharcharset xxx, and xxx is the encoding name. Set the character set in the https header of the webpage file on the server as your default xxx character set. This line adds a header ("content-type: text/html; charset = xxx") to each file "). Now we can see why the meta settings are UTF-8 and the browser can always use gb2312.
If the webpage contains a header ("content-type: text/html; charset = xxx"), change the default character set to the character set you set, so this function will always be useful. Add "#" before adddefacharcharset xxx, comment out this sentence, and the page does not contain header ("content-type... "), Then it is the time for the meta tag to take effect.
Header ("content-type: text/html; charset = xxx ")
If you are a web programmer, add a header ("content-type: text/html; charset = xxx") to each page to ensure that it is correctly displayed on any server, high portability.
As for adddefacharcharset xxx, if you want to comment it out, you can see it. I commented it out, but I also need to write the header () to write the page so that it can be displayed on the server.
II. database code
Before the PHP program queries the database, it first executes mysql_query ("set names xxxx"). xxxx is the code of your webpage (charset = xxxx). if charset = utf8 in the webpage, then xxxx = utf8. if charset = gb2312 in the webpage, then xxxx = gb2312. almost all WEB programs have a public code to connect to the database and put it in a file, in this file, add mysql_query ("set names.
Set names displays the character sets used in the SQL statements sent by the client. Therefore, the set names 'utf-8' statement tells the server that "the information sent from this client will use the UTF-8 character SET ". It also specifies the character set for the results sent from the server back to the client. (For example, if you use a SELECT statement, it indicates the character set used by the column value .)
Author: "dancer blog"
Authorization 1. use META http-equiv = content-type content = text/html; charset = xxx tag to set page encoding. the purpose of this tag is to declare the character set used by the client browser...