删除DOM警告PHP [英] Remove DOM Warning PHP

查看:76
本文介绍了删除DOM警告PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

  $ strhtml = file_get_contents('05001400300320100033100.html'); 
$ dochtml =新的DOMDocument();
$ dochtml-> loadHTML($ strhtml);
$ elm = $ dochtml-> getElementById(’upPanelActuciones’);
print $ dochtml-> saveXml($ elm);

我收到此警告:

 警告:DOMDocument :: loadHTML()[domdocument.loadhtml]:在实体中解析属性名称时出错,在C:\AppServ\www\video01\sector2\dom3中行:674 .php在第10行

警告:DOMDocument :: loadHTML()[domdocument.loadhtml]:开头和结尾标记不匹配:实体中的div和td,在C:\AppServ中的第1019行第10行上的wwwectorvideo01\sector2 ondom3.php

警告:DOMDocument :: loadHTML()[domdocument.loadhtml]:打开和结束标签不匹配:实体,行中的div和td :第10行的C:\AppServ\www\video01\sector2\dom3.php中的1020

警告:DOMDocument :: loadHTML()[domdocument.loadhtml]:打开和结束标签不匹配:实体中的div和td,第10行,C:\AppServ\www\video01\sector2\dom3.php,第10行,$ 102

我无法处理html(我知道html文件有错误),因此有办法消除此警告吗? (未显示)。



提前感谢您的帮助。

解决方案

< blockquote>

DOMDocument非常擅长处理不完美的标记,但是当它执行时,
会在所有位置发出警告。



此处未对此进行详细记录。解决方案是将
单独实现以处理这些错误。



在调用loadHTML之前设置libxml_use_internal_errors(true)。
可以防止错误冒泡到您的默认错误处理程序。
然后,您可以使用其他libxml错误
函数来获取它们(如果需要)。



您可以在此处找到更多信息
http://www.php.net/manual/zh-CN/ref.libxml.php


正确的方法处理DOMDocument错误的方法是:

 <?php 

//启用用户错误处理
var_dump(libxml_use_internal_errors(true));

//加载文档
$ doc = new DOMDocument;

if(!$ doc-> load('file.xml')){
foreach(libxml_get_errors()as $ error){
//在此处处理错误
}

libxml_clear_errors();
}

?>


I have this code:

$strhtml = file_get_contents('05001400300320100033100.html');
$dochtml = new DOMDocument();
 $dochtml->loadHTML($strhtml);
 $elm = $dochtml->getElementById('upPanelActuciones');
 print $dochtml->saveXml($elm);

Im getting this warning:

      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

I can't manipulate the html (i Know that the html file have errors) so there is a way to remove this warnings? (no show).

Thanks in advance for your help.

解决方案

DOMDocument is very good at dealing with imperfect markup, but it throws warnings all over the place when it does.

This isn't well documented here. The solution to this is to implement a separate aparatus for dealing with just these errors.

Set libxml_use_internal_errors(true) before calling loadHTML. This will prevent errors from bubbling up to your default error handler. And you can then get at them (if you desire) using other libxml error functions.

You can find more info here http://www.php.net/manual/en/ref.libxml.php

The correct way to deal with DOMDocument errors is this:

<?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();
}

?>

这篇关于删除DOM警告PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆