PHP libxml 错误代码 68 htmlParseEntityRef:无名称
PHP libxml error code 68 htmlParseEntityRef: no name
我正在使用 PHP libxml 库来处理 xml 文件。作为此过程的一部分,我设置 libxml_use_internal_errors(true),从文件中加载 xml 并使用 libxml_get_errors() 检查是否有任何 xml 错误。
这是我的代码:
$filename = $local_dir . $file;
$file_parts = pathinfo($filename);
if ( $file_parts['extension'] != 'xml' ) continue;
$xml_string = file_get_contents($filename);
// check for valid xml
libxml_use_internal_errors(true);
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML( $xml_string );
$xml_errors = libxml_get_errors();
if (!empty($xml_errors) ) {
echo 'There is an error in file: ' . $file . '<br>';
print_r($xml_errors);
libxml_clear_errors();
continue;
}
此代码是处理多个 xml 文件的循环的一部分,$filename 变量设置正确。
在我的本地 Wamp 服务器上没有返回任何错误,但是当我在开发服务器上运行它时,一些 xml 文件出现以下错误:
LibXMLError 对象(
[level] => 2
[code] => 68
[column] => 202
[message] => htmlParseEntityRef:无名称
[file] =>
[line] => 1
)
谁能解释一下这个错误是什么意思?
谢谢
安东尼拉文
在您的 XML 中的某处是一个空 &
,它是为字符引用的开头保留的。将其更改为 &
.
注:
如果您使用 $doc->load($filename)
而不是 file_get_contents
和 loadXML
,您将在错误中获得更完整的诊断信息。
我正在使用 PHP libxml 库来处理 xml 文件。作为此过程的一部分,我设置 libxml_use_internal_errors(true),从文件中加载 xml 并使用 libxml_get_errors() 检查是否有任何 xml 错误。
这是我的代码:
$filename = $local_dir . $file;
$file_parts = pathinfo($filename);
if ( $file_parts['extension'] != 'xml' ) continue;
$xml_string = file_get_contents($filename);
// check for valid xml
libxml_use_internal_errors(true);
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML( $xml_string );
$xml_errors = libxml_get_errors();
if (!empty($xml_errors) ) {
echo 'There is an error in file: ' . $file . '<br>';
print_r($xml_errors);
libxml_clear_errors();
continue;
}
此代码是处理多个 xml 文件的循环的一部分,$filename 变量设置正确。
在我的本地 Wamp 服务器上没有返回任何错误,但是当我在开发服务器上运行它时,一些 xml 文件出现以下错误:
LibXMLError 对象(
[level] => 2
[code] => 68
[column] => 202
[message] => htmlParseEntityRef:无名称
[file] =>
[line] => 1
)
谁能解释一下这个错误是什么意思?
谢谢
安东尼拉文
在您的 XML 中的某处是一个空 &
,它是为字符引用的开头保留的。将其更改为 &
.
注:
如果您使用 $doc->load($filename)
而不是 file_get_contents
和 loadXML
,您将在错误中获得更完整的诊断信息。