Questions about iconv and mb_detetct_encoding in the mb_convert_encoding-php

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.