Update 6.11 After looking more closely at the comments on 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, in the detection of GBK mb_detect_encoding return is cp936
I need to judge this value and then use Iconv (' GBK ', ' utf-8 ', $str) to convert, if it's something else.
GBK corresponds to the corresponding cp936, how should I match in the detection method? "
$a=' "name":"默认排序", "key":"sort", "value":"", "status":"0", "isSelected": "0" }';// var_dump($b);$b=iconv('UTF-8', 'GBK', $a);$x=mb_detect_encoding($a);$y=mb_detect_encoding($b);var_dump($x,$y);var_dump($b);
The sample is in the browser code UTF8, after the code changed to GBK Chinese normal display
Question: 1, why the Iconv converted string is still utf-8
2, mb_detect_encoding exactly is what code to detect
3, the production of such a problem, I can still use mb_convert_encoding transcoding?
Reply content:
Update 6.11 After looking more closely at the comments on 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, in the detection of GBK mb_detect_encoding return is cp936
I need to judge this value and then use Iconv (' GBK ', ' utf-8 ', $str) to convert, if it's something else.
GBK corresponds to the corresponding cp936, how should I match in the detection method? "
$a=' "name":"默认排序", "key":"sort", "value":"", "status":"0", "isSelected": "0" }';// var_dump($b);$b=iconv('UTF-8', 'GBK', $a);$x=mb_detect_encoding($a);$y=mb_detect_encoding($b);var_dump($x,$y);var_dump($b);
The sample is in the browser code UTF8, after the code changed to GBK Chinese normal display
Question: 1, why the Iconv converted string is still utf-8
2, mb_detect_encoding exactly is what code to detect
3, the production of such a problem, I can still use mb_convert_encoding transcoding?
First, look at this.
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, consider using the Servicesjson class.
The solution is: change Utf-8 to UTF8