Solutions to various php application garbled characters _ PHP Tutorial

Source: Internet
Author: User
Solutions to various php application garbled issues. 1) use tags to set page encoding the role of this tag is to declare the client browser with what character set encoding to display the page, xxx can be GB2312, GBK, UTF-8 (different from MySQL, 1) use tags to set 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.

Note that HTML information is only a declaration, indicating that the server has passed the 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 the text, the function is basically the same as that in the tag. you can see that the characters are similar to those in the first one. 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 http headers and HTML information:

The http header is the string sent by the server before the server sends HTML information to the browser over http. The tag belongs to the HTML information, so the content sent by the header () first arrives in the browser. the common point is that the priority of the header () is higher than (I don't know if I can say this ). If a php page contains both the header ("content-type: text/html; charset = xxx") and the browser recognizes the http header of the former 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.

3) adddefacharcharset

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 http 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 UTF-8 is clearly set, 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.

The preceding priorities are listed below:

. Header ("content-type: text/html; charset = xxx ")

.. Adddefacharcharset xxx

..

If you are a web programmer, we recommend that you add a header ("content-type: text/html; charset = xxx") to each page "), in this way, it can be correctly displayed on any server, and the portability is also strong.

4) default_charset configuration in php. ini:

Default_charset = "gb2312" in php. ini defines the default language character set of php. It is generally recommended to comment out this line so that the browser can automatically select a language based on the charset in the web page header, rather than making a mandatory provision, so that web services in multiple languages can be provided on the same server.

Solution to Chinese character garbled characters intercepted by PHP: application of the mb_substr function
Mysql Chinese garbled solution highlights

Http://www.bkjia.com/PHPjc/321816.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321816.htmlTechArticle1) use tags to set the 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 (different from MySQL ,...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.