从 PHP DOC simplexml_load_file选项应该是 int 而不是数组
代替
$xml = simplexml_load_file($url, "SimpleXMLElement", array(LIBXML_NOERROR, LIBXML_ERR_NONE));
^------- You are using array
和
$xml = simplexml_load_file($url, "SimpleXMLElement", LIBXML_NOERROR | LIBXML_ERR_NONE);
除了抑制此错误,您还可以使用Tidy包修复 xml。
示例bad.xml
<Family>
<name>Hankre</name>
<adults>2</adults>
<kids > 16 </kids>
<food>
<tag>Nice </tag>
<tag>Food </tag>
<tag />
修复 XML
$config = array(
'indent' => true,
'clean' => true,
'input-xml' => true,
'output-xml' => true,
'wrap' => false
);
$tidy = new Tidy();
$xml = $tidy->repairfile($badXML, $config);
echo $xml;
输出
<Family>
<name>Hankre</name>
<adults>2</adults>
<kids>16</kids>
<food>
<tag>Nice</tag>
<tag>Food</tag>
<tag />
</food>
</Family>