Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php和xpath获取html标记后的文本_Php_Html_Xpath - Fatal编程技术网

使用php和xpath获取html标记后的文本

使用php和xpath获取html标记后的文本,php,html,xpath,Php,Html,Xpath,我从网页的一个片段中获得了以下html: <div id="box"> <br> Your word(s): <br> <br> functionally <br> <br> <br> 这不会返回任何内容。如果我只备份到/div我当然会得到框的全部内容。如何提取第二个后面的单词。我的单词总是在第三个之后 看起来很简单,但我还是想不起来。试试这样的查询 $textNodes = $xpath->query(

我从网页的一个片段中获得了以下html:

<div id="box">
<br>
Your word(s):
<br>
<br>
functionally
<br>
<br>
<br>
这不会返回任何内容。如果我只备份到
/div
我当然会得到框的全部内容。如何提取第二个

后面的单词。我的单词总是在第三个

之后


看起来很简单,但我还是想不起来。

试试这样的查询

$textNodes = $xpath->query('//div[@id="box"]/br[3]/following-sibling::text()[1]');
在这里工作-

这里的关键是
后面的兄弟姐妹


信息
a1b2
a2
获取b2 after标记。xpath如下所示。
//dl/dd/a[1]/以下同级::text()

谢谢。它确实有效,而且您实际上允许我用xpath和follow-sibling.KiloJKilo扫清了一大障碍。为什么不选择我的答案呢?键位于以下同级::text()。我只是不告诉你问题的详细答案。
$textNodes = $xpath->query('//div[@id="box"]/br[3]/following-sibling::text()[1]');
<dl>
        <dt>info</dt>
        <dd>
            <a>a1</a>b2
            <a>a2</a>
        </dd>
    </dl>