In case of inconsistent PHP, MySQL, and browser encoding, how can we ensure normal resolution?

Source: Internet
Author: User
Tags what php
The ideal situation is to unify the three codes into gbk or UTF-8, so that resolution is normal. But how can it be different? For example, -- PHP encoding is UTF-8 -- MySQL encoding is UTF-8 -- the browser encoding is gbk. in this case, you only need to consider PHP and browsing.

The ideal situation is to unify the three codes into gbk or UTF-8, so that resolution is normal. But how can it be different? For example, -- PHP encoding is UTF-8 -- MySQL encoding is UTF-8 -- the browser encoding is gbk. in this case, you only need to consider PHP and browsing...

The ideal situation is to unify the three codes into gbk or UTF-8, so that resolution is normal. But how can it be different?

For example:

-- The PHP code is UTF-8.

-- MySQL is UTF-8 encoded

-- The browser code is gbk.

At this time, you only need to consider the PHP and the browser, because the PHP and MySQL encoding is consistent, you can not consider. How can I tell the browser that what PHP returns to the browser is UTF-8, so please use UTF-8 for parsing?

Answer:

(1) one of the methods is the header function we use in PHP. Header ("Content-type: text/html; charset = utf-8 ");

(2) method 2 is set in the meta tag of html code.

If the encoding between PHP and MySQL is not uniform, how can we tell each other their own encoding?

Answer:

(1) one of the methods is to modify the encoding when the MySQL server receives PHP Data and returns the data to PHP in MySQL. set character_set_client = utf8; it indicates that the current PHP code sent from the MySQL server is utf8. Set character_set_result = utf8; indicates that the MySQL server currently supports utf8 only in PHP.

(2) method 2 is a simplified method. Set names utf8 directly in the PHP code, indicating that PHP only sends and accepts utf8 encoding. Simplified in method 1 above.

Disclaimer: This article only represents the author's personal opinion and has nothing to do with this site. Its originality, as well as the statement text and content in this article have not been confirmed by this site, this article and all or part of the content, the authenticity, integrity, timeliness of this site do not make any warranty or commitment, for your reference only, please verify the relevant content on your own.

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.