标签:php
有人可以解释为什么在下面的最后三个测试中输出是ASCII吗?
echo mb_internal_encoding(); // UTF-8
$str = 'foobar';
echo mb_check_encoding($str, 'UTF-8'); // true
echo mb_detect_encoding($str); // ASCII
$encoded = utf8_encode($str);
echo mb_detect_encoding($encoded); // ASCII
$converted = mb_convert_encoding($str, 'UTF-8');
echo mb_detect_encoding($converted); // ASCII
解决方法:
那是因为foobar中没有无法用ASCII表示的字符.
mb_check_encoding($str,’UTF-8′)有效,因为ASCII文本与UTF-8天生兼容(故意这样)
但是在没有多字节字符的情况下,两者之间没有明显的区别.证明:’foobar’=== utf8_encode(‘foobar’)// true
标签:php
来源: https://codeday.me/bug/20190608/1196957.html