PHP how to detect the file encoding, the user uploads a file, the page shows the content, the entire website is UTF-8, if the user uploads a GB file, it shows garbled. Can use mb_convert_encoding ($ text, & nbsp; & quot; UTF-8 & quot;, & nbsp; & quot; GBK & PHP how to detect file encoding?
The user uploads a file, the page shows the content, the whole website is UTF-8, if the user uploads a GB file, it shows garbled.
You can use mb_convert_encoding ($ text, "UTF-8", "GBK"); to convert, but how do you determine that the user uploads a GB-encoded file?
------ Solution --------------------
Mb_check_encoding -- Check if the string is valid for the specified encoding
------ Solution --------------------
It seems that an error has been written upstairs.
Mb_detect_encoding ($ string)
------ Solution --------------------
Iconv can also be ....
------ Solution --------------------
$ Temstr = file_get_contents ($ path );
$ Encode = mb_detect_encoding ($ temstr, "ASCII, UTF-8, CP936, EUC-CN, BIG-5, EUC-TW ");
$ Temstr = mb_convert_encoding ($ temstr, "CP936", $ encode );
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.