Php + mysql garbled problem guidance database environment: redhat AS5 + mysql5.0.4 UTF8 encoding
WEB environment: UTF8 encoding for the win2003 nginx1.5 php5.2.17 page.
Other instructions: an application (purchased) uses the mysql5.0.4 Database. I now use php to write a website to display part of the content in the database. one field stores the name ,, garbled characters are displayed on the page, and the same garbled code is displayed when I use mysql management tools. I used to write this website using ASP. NET (C #) write, at that time is to try a variety of encoding, and finally determine the ISO8599-1 encoding to UTF8 can be normally displayed. At that time, the method to handle garbled text was to use a function for transcoding. the reading was converted to UTF8. Currently, PHP is not familiar with it and there is no solution.
The following is the code (C #) I used to solve this garbled problem. I don't know how to change it to PHP,
// Read is to convert private string ISO8599ToUTF8 (string str) {Encoding UTF_8 = System. text. encoding. getEncoding ("UTF-8"); Encoding ISO = System. text. encoding. getEncoding ("ISO8859-1"); byte [] iso = ISO. getBytes (str); return UTF_8.GetString (iso );}
Reply to discussion (solution)
You can retrieve the fields of garbled fields from the database, for example, save them to $ s.
Then echo base64_encode ($ s); paste the result
Thank you for your reply. what you see is that the result "********************************** will certainly not be base64-encoded.
Assume that your garbled content is in $ s
Echo base64_encode ($ s );
Post result
Yiyi AngelIs that the answer?
The hexadecimal internal code of the garbled text you posted is efbbbfc395c39bc392c3adc38cc3acc38ac2b9.
Efbbbf is the BOM header of the UTF-8 character set.
Apparently, you executed the set names utf8 command before reading data.
C395c39bc392c3adc38cc3acc38ac2b9 is the result of converting latin1 to UTF-8 encoding.
Latin1 (general European character set 1) is iso 8859-1
After iconv ('utf-8', 'latin1', substr ($ s, 3 ));
After transcoding, The Hex Angel's hexadecimal internal code is d5dbd2edcceccab9.
It is obviously a gbk encoded string
Thank you!