Dom xPath loadHTML在“的表元素上出错”;意外结束标记“;

Dom xPath loadHTML在“的表元素上出错”;意外结束标记“;,dom,error-handling,html-parsing,Dom,Error Handling,Html Parsing,当我的内容包含下面的表标记时,我遇到一个错误。以下是错误消息: 警告:DOMDocument::loadHTML()[DOMDocument.loadHTML]:意外结束标记:实体中的列,行:2 这在我的代码中引用了此行: $dom->loadHTML(strtolower($post->post_content)); 我的内容包含此表标记 <table style="height: 658px;" border="0" cellspacing

当我的内容包含下面的表标记时,我遇到一个错误。以下是错误消息:

警告:DOMDocument::loadHTML()[DOMDocument.loadHTML]:意外结束标记:实体中的列,行:2

这在我的代码中引用了此行:

$dom->loadHTML(strtolower($post->post_content));
我的内容包含此表标记

<table style="height: 658px;" 
       border="0" 
       cellspacing="0" 
       cellpadding="0" 
       width="472">
    <colgroup>
        <col width="188"></col>
        <col width="590"></col>
    </colgroup>
    <tbody>
        <tr height="20">
            <td width="188" height="20"></td>
            <td width="590"></td>
        </tr>
    </tbody>
</table>

我只是在猜测,但是由于您的col元素没有内部值,请尝试改用no-end标记。因此,
而不是使用

A@Nikky9696:谢谢你的提示。假设这样做有效,我如何修改函数以抑制错误或克服错误?数据总是动态的,所以我不知道html标签是空的还是非空的。你能控制生成吗?我知道我们必须修改我们的一个工具来生成空元素和值为value的元素谢谢!!!为我工作!
function doTheParse($heading)
{
global $post;
$content = $post->post_content;
if($content=="") return false;
$keyword = trim(strtolower(rseo_getKeyword($post)));
$dom = new DOMDocument;
$dom->loadHTML(strtolower($post->post_content));
$xPath = new DOMXPath($dom);
switch ($heading)
    {
    case "img-alt": return $xPath->evaluate('boolean(//img[contains(@alt, "'.$keyword.'")])');
    default: return $xPath->evaluate('boolean(/html/body//'.$heading.'[contains(.,"'.$keyword.'")])');
    }
}