How to determine the data encoding of file_get_contents

Source: Internet
Author: User
How to determine file_get_contents to the data is what encoding, such as the question, EUC-CN is the most commonly used expression of GB2312. The "GB2312" on the browser encoding table usually refers to the "EUC-CN" notation. However, if you use mb_detect_encoding, you cannot get the correct result. how do you determine the encoding of the data in the list & quot; gb2312 file_get_contents?
Example

------ Solution --------------------
EUC-CN is the most commonly used representation of GB 2312. The "GB2312" on the browser encoding table usually refers to the "EUC-CN" notation.

However, you cannot get the correct result by using mb_detect_encoding.
You can call the encoding location in the list "gb2312, gbk, UTF-8"
------ Solution --------------------
Encoding determines content, content cannot determine encoding,
For example, to see a gbk Chinese character, can also be seen as two ISO-8859-1 characters
Therefore, mb_detect_encoding can only be guessed. since it is a guess, it cannot be completely correct (in fact, it is not absolutely correct)

For the content obtained by file_get_contents, if it is a web page, you can use meta to determine,
Without such information, you can only "guess"
------ Solution --------------------
Discussion

Encoding determines content, content cannot determine encoding,
For example, to see a gbk Chinese character, can also be seen as two ISO-8859-1 characters
Therefore, mb_detect_encoding can only be guessed. since it is a guess, it cannot be completely correct (in fact, it is not absolutely correct)

For the content obtained by file_get_contents, if it is a web page, you can use meta to determine,
Without such information, you can only "guess"

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.