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.