我有这个代码:
$strhtml = file_get_contents('05001400300320100033100.html');
$dochtml = new DOMDocument();
$dochtml->loadHTML($strhtml);
$elm = $dochtml->getElementById('upPanelActuciones');
print $dochtml->saveXml($elm);
我收到这个警告:
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: error parsing attribute name in Entity, line: 674 in C:'AppServ'www'video01'sector2'dom3.php on line 10
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Opening and ending tag mismatch: div and td in Entity, line: 1019 in C:'AppServ'www'video01'sector2'dom3.php on line 10
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Opening and ending tag mismatch: div and td in Entity, line: 1020 in C:'AppServ'www'video01'sector2'dom3.php on line 10
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Opening and ending tag mismatch: div and td in Entity, line: 1022 in C:'AppServ'www'video01'sector2'dom3.php on line 10
我无法操作html(我知道html文件有错误),所以有办法删除这些警告吗?(没有露面)。
提前感谢您的帮助。
DOMDocument非常擅长处理不完美的标记,但是当它这样做的时候,到处都是警告。
这里没有很好的记录。解决方案是用于处理这些错误的单独的设备。
在调用loadHTML之前设置libxml_use_internal_errors(true)。这将防止错误冒泡到默认的错误处理程序中。然后,您可以使用其他libxml错误来获取它们(如果您愿意的话)功能。
你可以在这里找到更多信息http://www.php.net/manual/en/ref.libxml.php
处理DOMDocument错误的正确方法是:
<?php
// enable user error handling
var_dump(libxml_use_internal_errors(true));
// load the document
$doc = new DOMDocument;
if (!$doc->load('file.xml')) {
foreach (libxml_get_errors() as $error) {
// handle errors here
}
libxml_clear_errors();
}
?>