Home > Article > Backend Development > What to do if php cp936 is garbled?
php cp936 garbled solution: 1. Open the corresponding PHP file; 2. Find the "mb_convert_encoding($str, 'UTF-8', 'CP936');" code; 3. Use "iconv( 'utf-8', 'latin1//IGNORE', $str);" method can be used to transcode.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
php cp936 What should I do if the code is garbled?
php cp936 to utf8 Chinese encoding conversion Chinese character garbled solution solution
Problem description:
I encountered a problem today,
Chinese strings such as ??°??£è???¥¢?
¨é??
need to be converted to UTF8, so the PHP function is called.
mb_convert_encoding($str, 'UTF-8', 'CP936');
The result after the conversion is:
Meng 聬聨 mang 聨橷 Blind Lu Luo Mao Lu Lu Menglou ridge mang 聟瓓Maolian 聍聬聤ermang 聛 stove
The actual required result is:
Postmodern light luxury all-copper chandelier
When I encountered this problem, I searched on Baidu and found that I couldn’t find a solution
It’s best to do it yourself Try it, solve it, record it and share it with those in need to prevent it from happening again!
The solution is as follows:
Use iconv('utf-8', 'latin1//IGNORE', $str);
Attachment:
function toUtf8($str) { $encode = mb_detect_encoding($str, array('CP936', "ASCII","GB2312","GBK",'UTF-8','BIG5')); if ($encode == 'UTF-8') { return $str; } elseif ($encode == 'CP936') { return iconv('utf-8', 'latin1//IGNORE', $str); } else { return mb_convert_encoding($str, 'UTF-8', $encode); } }
Recommended study: "PHP Video Tutorial"
The above is the detailed content of What to do if php cp936 is garbled?. For more information, please follow other related articles on the PHP Chinese website!