Phpfile_get_contents garbled characters

Source: Internet
Author: User
Phpfile_get_contents garbled problem my website's php file is in UTF-8 format. I hope file_get_contents can read a website in gb2312 format, so garbled characters are displayed. The details are as follows: the gb2312 format contains UTF-8 garbled php files. to solve the garbled problem, I only intend to change the php file read from the webpage to the gb2312 format, other php file_get_contents garbled characters with UTF-8 format reserved
My website's php file is in UTF-8 format. one website that I want file_get_contents to read is in gb2312 format, so garbled characters are displayed. The details are as follows:

The gb2312 format contains UTF-8 garbled characters.

There are a lot of PHP files on the website to solve the garbled problem. I just want to change the php file that reads the webpage to the gb2312 format, while others retain the UTF-8 format. However, this file contains other PHP files, and the file contains several other files ......

Another solution is to convert the content obtained by file_get_contents into UTF-8 format using iconv, but the css file remains unchanged. at the same time, some webpages may contain special symbols, encoding conversion causes loss. some webpages only get one segment.

Ask for solutions ......

------ Solution --------------------
Some iconv () functions cannot be converted. you can use the mb_convert_encoding () function to convert the code.
------ Solution --------------------
The second solution is better. after iconv conversion, the webpage content is normal and will not be garbled.

Iconv ("GB2312", "UTF-8 // transcoder", $ data );
Iconv ("GB2312", "UTF-8 // IGNORE", $ data );

The second parameter, in addition to specifying the encoding to be converted, can also add two suffixes: // transcoder and // IGNORE, // Transcoder automatically converts a character that cannot be directly converted into one or more similar characters. // IGNORE ignores the characters that cannot be converted, by default, the result is truncated from the first invalid character.


Or use GBK to replace gb2312,
Iconv ("GBK", "UTF-8", $ data );

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.