获取节点的文本内容,但忽略子节点 [英] Get the text content of a node, but ignore child nodes

查看:63
本文介绍了获取节点的文本内容,但忽略子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<foo>
  a
  <bar> b </bar>
</foo>

$foo->textContent$foo->nodeValue都返回a b.

如何仅获取a(节点中的文本,而没有任何子节点中的文本)

How can I get just a (the text from the node, without text from any child nodes)

推荐答案

使用firstChild:

$foo->firstChild->textContent;

这篇关于获取节点的文本内容,但忽略子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆