Learning php string encoding conversion and determination

Source: Internet
Author: User
Learning php string encoding conversion and determination
This article introduces a piece of code for transcoding and judgment of string encoding in php programming. if you need it, you can take it as a reference. In php, GBK and UTF-8 encoding conversion are often required. for example, json_encode in PHP itself does not support GBK encoding. There are two library functions that support encoding conversion. Generally, the iconv function can be thought of. for example:
     However, iconv can only solve the problem of pre-known encoding. if the string encoding is unknown, you need to first detect its encoding. in this case, the mb_string extension library may be used:
      However, mb_detect_encoding has a hard injury, which often results in inaccurate judgment. You can refer to the following solutions:
       After obtaining the string encoding information, you can use iconv or mb_convert_encoding for encoding conversion.

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.