我有一个包含此类信息的源文件
<div itemprop="comment" itemscope itemtype="http://schema.org/UserComments" class="comment_item" id="comment_60857544">
<meta itemprop="discusses" content="http://source.com/permalink/comments/60857544" />
<a id="c60857544"></a>
<p>
<div class="pp-container">
<img class="gravatar" src="http://static.source.com/sharedDocs/images/frontend/default_pp.png" />
</div>
a comment is available here
</p>
<div class="itemfooter">comment information
</div>
代码
$comment_id = $xpath->query("a[@id]", $commentNode)->item(0)->getAttribute('id');
正确检索评论ID 但评论内容检索不起作用
$tmpdom = new DomDocument();
if ($titleNode = $xpath->query('h3', $commentNode)->item(0))
{
$tmpnode = $tmpdom->createElement('p');
$tmpnode->appendChild($tmpdom->createElement('strong', esc_html($titleNode->textContent)));
$tmpdom->appendChild($tmpnode);
}
foreach ($xpath->query('//p', $commentNode) as $comment_p)
{
$tmpdom->appendChild($tmpdom->importNode($comment_p, true));
}
$data['comment_content'] = trim(preg_replace('#<p>[\s]*</p>#U', '', $tmpdom->saveHTML()));
有什么想法吗?