XPath表达式在<br>标记后获取字符串

时间:2019-06-11 17:57:22

标签: php xml xpath domxpath

我正在尝试获取article/div/p中的内容,但仅获取<br>标记后的日期。怎么做?

<article>
    <h2>Man rescued after falling into Crater Lake</h2>
    <p class="summary highlight">
        Man rescued after falling 800 feet into Crater Lake in Oregon
    </p>

    <div class="body">
       <p>by Joe Sutton<br>
            June 11, 2019
        </p>
    </div>
</article>
$expression = "article/div/p";

1 个答案:

答案 0 :(得分:1)

此XPath,

//br/following-sibling::text()

将选择br之后的所有后续同级文本节点。