Iconv encoding conversion in php to solve Chinese garbled characters _ PHP Tutorial

Source: Internet
Author: User
Iconv encoding conversion in php solves Chinese garbled characters. Use the iconv function to convert the captured UTF-8 encoded page to gb2312, it is found that only the iconv function can be used to convert the captured data to code data without any reason. some code is as follows: The iconv function is used to convert the captured UTF-8 encoded page to gb2312, it is found that only the iconv function can be used to convert the captured data into less data for no reason.
The code is as follows:

Echo $ str = 'Hi, it's coffee sale! ';
Echo'
';

Echo iconv ('gb2312', 'utf-8', $ str); // Encode the string from GB2312 to UTF-8
Echo'
';

Echo iconv_substr ($ str, 1, 1, 'utf-8'); // truncate by number of characters rather than bytes
Print_r (iconv_get_encoding (); // Obtain the encoding information of the current page.

Echo iconv_strlen ($ str, 'utf-8'); // you can specify the length of the encoded string.

// This is also applicable.

$ Content = iconv ("UTF-8", "gbk // transcoder", $ content );
?>

Iconv ("UTF-8", "GB2312 // IGNORE", $ data)
Ignore indicates that the conversion error is ignored. without the ignore parameter, all strings after this character cannot be saved.

This iconv () function is built in php5.

Then, I found that only the iconv function can be used to convert the captured data into code, and the following code is missing for no reason...

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.