我有一些html试图检索文本,但没有<h1>
标签内容。
$html = '<div class="mytext">
<h1>Title of document</h1>
This is the text that I want, without the title.
</div>';
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$xp = new DOMXpath($dom);
foreach($xp->query('//div[@class="mytext"]') as $node) {
$description = $node->nodeValue;
echo $description;
}
最终结果应为:This is the text that I want, without the title.
当前为:Title of document This is the text that I want, without the title
我如何只获取没有h1标签的文本?
答案 0 :(得分:1)
尝试一下:
y