PHP uses mb_detect_encoding to detect string encoding
Source: Internet
Author: User
KeywordsPHP uses mb_detect_encoding to detect string encoding
PHP generally uses the Mb_detect_encoding function for string coding, but many people have encountered the problem of identifying coding errors, such as with GB2312 and UTF-8, or UTF-8 and GBK (which is mainly about cp936), Online said is because the character is short, mb_detect_encoding will appear false.
The purpose of this code is to detect whether the encoding of a string is UTF-8, and then convert to GBK.
But when $keytitle = '%d0%be%c6%ac '; When The test results are UTF-8. This bug is not really a bug, writing programs should not be too dependent on mb_detect_encoding, when the string is shorter, the detection result is very likely to deviate.
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.