Update6.11 after carefully reading the comments about mb_detect_encoding in the php manual, {code ...} I have another question: when detecting gbk, mb_detect_encoding returns cp936. I need to judge this value and then use iconv (& #039; gbk & #039;, & #039; UTF-8 & #039;, $ str...
Update 6.11 after carefully reading the comments about mb_detect_encoding in the php manual,
If you try to use mb_detect_encoding to detect whether a string is valid UTF-8, use the strict mode, it is pretty worthless otherwise.
I have another question: when detecting gbk, mb_detect_encoding returns cp936
I need to judge this value and use iconv ('gbk', 'utf-8', $ str) for conversion.
Gbk corresponds to cp936. How should I perform matching in the detection method?
$ A = '"name": "Default sorting", "key": "sort", "value": "", "status": "0", "isSelected ": "0"} '; // var_dump ($ B); $ B = iconv ('utf-8', 'gbk', $ ); $ x = mb_detect_encoding ($ a); $ y = mb_detect_encoding ($ B); var_dump ($ x, $ y); var_dump ($ B );
The sample image is displayed normally after the encoding is changed to gbk in the browser encoding utf8.
Question: 1. Why is the iconv converted string still UTF-8?
2. What encoding is mb_detect_encoding?
3. Can I use mb_convert_encoding for transcoding?
Reply content:
Update 6.11 after carefully reading the comments about mb_detect_encoding in the php manual,
If you try to use mb_detect_encoding to detect whether a string is valid UTF-8, use the strict mode, it is pretty worthless otherwise.
I have another question: when detecting gbk, mb_detect_encoding returns cp936
I need to judge this value and use iconv ('gbk', 'utf-8', $ str) for conversion.
Gbk corresponds to cp936. How should I perform matching in the detection method?
$ A = '"name": "Default sorting", "key": "sort", "value": "", "status": "0", "isSelected ": "0"} '; // var_dump ($ B); $ B = iconv ('utf-8', 'gbk', $ ); $ x = mb_detect_encoding ($ a); $ y = mb_detect_encoding ($ B); var_dump ($ x, $ y); var_dump ($ B );
The sample image is displayed normally after the encoding is changed to gbk in the browser encoding utf8.
Question: 1. Why is the iconv converted string still UTF-8?
2. What encoding is mb_detect_encoding?
3. Can I use mb_convert_encoding for transcoding?
First, read here
Http://cn2.php.net/manual/zh/function.mb-detect-encoding.php
Http://cn2.php.net/manual/zh/function.mb-detect-order.php
Ps.
If you want to output json Chinese characters, consider using the servicesjson class.
Solution: Change UTF-8 to utf8