Let's take a look! Solution-php Tutorial

Source: Internet
Author: User
Let's take a look! Younger brother I encountered this problem: My Front-end has a query box (written in Php, encoding format is GBK), the background database encoding format for UTF-8, now you have entered Chinese characters in the input box, but garbled characters are displayed on the background, so you cannot find the data displayed on the foreground. One method I have found is to use the encodeURI function in my javascript to convert the input Chinese characters into a hexadecimal sequence. then I want to find a php big master to help me look at it!
Younger brother I encountered this problem: My Front-end has a query box (written in Php, encoding format is GBK), the background database encoding format for UTF-8, now you have entered Chinese characters in the input box, but garbled characters are displayed on the background, so you cannot find the data displayed on the foreground. One method found now is to use the encodeURI function in javascript to convert the input Chinese characters into a hexadecimal sequence, then I want to find a php method to convert the sequence back into Chinese characters. What can I do!

------ Solution --------------------
1. use encodeURIComponent instead of encodeURI for url encoding conversion using js
Only in this way can gbk be converted into a UTF-8 url string
The server only needs urldecode to obtain UTF-8 data.

2. assume that you are using a mysql database.
This does not need to be so complicated. you only need to execute SQL commands after selecting the database.
Set names gbk
Yes. the encoding and conversion work will be completed by mysql.
------ Solution --------------------
On the php end, use mb_convert_encoding () to convert the encoding to gbk to UTF-8.

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.