ASCII字符被检测为有效的拉丁文1,但不是
cp1252
.
mb_detect_encoding("a",["ISO-8859-1"],true); // "ISO-8859-1"
mb_detect_encoding("a",["Windows-1252"],true); // false
80-9F范围内的附加字符可检测为:
mb_detect_encoding("\x80",["ISO-8859-1"],true); // "ISO-8859-1"
mb_detect_encoding("\x80",["Windows-1252"],true); // "Windows-1252"
但常见的扩展字符不是。拿这个
é
角色在
0xE9
.PHP将其检测为ISO,但不是超集:
mb_detect_encoding("\xE9",["ISO-8859-1"],true); // "ISO-8859-1"
mb_detect_encoding("\xE9",["Windows-1252"],true); // false
将附加字符转换为UTF-8需要使用Windows字符集,该字符集按预期工作:
mb_convert_encoding("a\xE9\x80","UTF-8","Windows-1252"); // aéâ¬
mb_convert_encoding("a\xE9\x80","UTF-8","ISO-8859-1"); // aé<control>
我可以接受这种限制(检测为ISO,转换为Windows),但我很想知道为什么会这样。