mb_detect_encoding detects ASCII as UTF-8?

試著忘記壹切 提交于 2019-11-29 07:19:52

Specifying a custom order, where ASCII is detected first, works.

mb_detect_encoding($val, 'ASCII,UTF-8,ISO-8859-15');

For completeness, the list of available encodings is at http://www.php.net/manual/en/mbstring.supported-encodings.php

You can specified explicitly

$val = mb_convert_encoding($val, 'UTF-8', 'ASCII');

EDIT:

$val = mb_convert_encoding($val, 'UTF-8', 'auto');

If you do not want to worry about what encodings you will allow, you can add them all

$encoding = mb_detect_encoding($val, implode(',', mb_list_encodings()));

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!