Use php to split string encoding

Source: Internet
Author: User
Tested in linux with php string encoding, suitable for detecting webpage encoding, provided that the mb series of functions are installed, which are generally installed in php. $ Content = file_get_contents ($ url); $ encode = mb_detect_encoding (use php to detect string encoding
The test passed in linux is suitable for detecting webpage encoding, provided that the mb series functions are installed, which are generally installed in php.

$ Content = file_get_contents ($ url); $ encode = mb_detect_encoding ($ content, 'cp936, UTF-8 '); // if it is CP936, it is gbk encoding, if it is a UTF-8, is UTF-8 encoded if ($ encode = 'cp936 ') {// call the function to convert to UTF-8 encoding, and finally ensure that it is UTF-8 $ content = mb_convert_encoding ($ content, 'utf-8', 'gbk');} echo $ content;

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.