Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中更改xml文档标签(utf编码)_Php_Xml - Fatal编程技术网

在php中更改xml文档标签(utf编码)

在php中更改xml文档标签(utf编码),php,xml,Php,Xml,我有一个奇怪的问题。我试图使用DomDocumnet函数加载一些xml文档,但它抛出了一个奇怪的警告: 警告:DOMDocument::load():标记为UTF-16但包含UTF-8内容的文档 没有其他错误或警告等。 当我从中手动编辑xml文件时 <?xml version="1.0" encoding="utf-16"?> to 到 它完美地处理它 我正在寻找一种解决方案,通过它,我可以在进一步处理之前编辑标题中的xml文件 提前谢谢 不是绝对的解决方案,而是在这种情况下解

我有一个奇怪的问题。我试图使用DomDocumnet函数加载一些xml文档,但它抛出了一个奇怪的警告:

警告:DOMDocument::load():标记为UTF-16但包含UTF-8内容的文档

没有其他错误或警告等。 当我从中手动编辑xml文件时

<?xml version="1.0" encoding="utf-16"?> to

它完美地处理它

我正在寻找一种解决方案,通过它,我可以在进一步处理之前编辑标题中的xml文件


提前谢谢

不是绝对的解决方案,而是在这种情况下解决这个问题的方法

在以字符串形式加载xml文档之后,在使用preg_replace函数进行进一步处理之前,只需将utf 16替换为utf8

$source_xml_file = file_get_contents($incorrect_xml_file, TRUE);
$corrected_xml_file= preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $source_xml_file);
$xmldoc->loadXML($corrected_xml_file);
$source\u xml\u file=file\u get\u contents($error\u xml\u file,TRUE);
$corrected_xml_file=preg_replace('/(