Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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-获取节点文本,包括<;br>;,没有子节点内容_Php_Xpath - Fatal编程技术网

PHP+;XPath-获取节点文本,包括<;br>;,没有子节点内容

PHP+;XPath-获取节点文本,包括<;br>;,没有子节点内容,php,xpath,Php,Xpath,我的html中有这个(以下的多个实例): 我越来越 这是第一行 及 这是第二行 作为单独的节点 按照另一个,我试过了 但这会产生“无效表达式”错误 有人能帮我解决我做错了什么吗 谢谢。您可以获得节点(),但不包括a元素: //div[@id="message"]/node()[not(self::a)] 演示(使用): $cat test.html 这是第一行 这是第二行 $xmllint test.html--xpath'//div[@id=“message”]/node()[not(sel

我的html中有这个(以下的多个实例):

我越来越

这是第一行

这是第二行

作为单独的节点

按照另一个,我试过了

但这会产生“无效表达式”错误

有人能帮我解决我做错了什么吗

谢谢。

您可以获得
节点()
,但不包括
a
元素:

//div[@id="message"]/node()[not(self::a)]
演示(使用):

$cat test.html
这是第一行
这是第二行 $xmllint test.html--xpath'//div[@id=“message”]/node()[not(self::a)]' 这是第一行
这是第二行

是非法的html

是一个单例标记,没有内容,也没有结束标记<代码>
是唯一有效的表单。既然你要的是
text()
,你就得到了。。子节点中的文本。您可能需要
innerHTML
,php dom不直接支持它。我的错误应该是
。谢谢,我更正了它。当我这样做时使用它:foreach($post作为$post的所有文章){echo$post->nodeValue;}。我听到“这是第一行,这是第二行”。我怎样才能让线路也断开呢?
This is the first line<br />This is the second line
$messages = $xpath->query('//div[@id="message"]/text()');
$xpath->query('//div[@id="message"][self::text() or self:br]');
AND
$xpath->query('//div[@id="message"]//nodes[self::text() or self:br]');
//div[@id="message"]/node()[not(self::a)]
$ cat test.html
<div id='message'>
    This is the first line<br/>
    This is the second line
    <a href='link'>link_A</a>
</div>
$ xmllint test.html --xpath '//div[@id="message"]/node()[not(self::a)]'
This is the first line<br/>
This is the second line