Php SimpleXMLElement Utf-16

时间:2015-10-14 12:20:23

标签: php encoding utf-8 simplexml utf-16

我想通过以下代码行创建SimpleXMLElement object

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-16"?><Data/>');

请注意编码标记显示UTF-16。因此发生错误Document labelled UTF-16 but has UTF-8 content

所以我这样试了:

$string = '<?xml version="1.0" encoding="UTF-16"?><Data/>';
var_dump(mb_detect_encoding($string, 'UTF-16,UTF-8')); //string(5) "UTF-8"
mb_convert_encoding($string, 'UTF-16', 'UTF-8');
var_dump(mb_detect_encoding($string, 'UTF-16,UTF-8')); //string(5) "UTF-8"

$xml = simplexml_load_string($string); //same error
$xml = new SimpleXMLElement($string); //same error

我对字符串/字符编码的理解不是那么好,也许我错过了一些明显的东西?

0 个答案:

没有答案