PHP DOMnode 对象包含一个 textContent和 nodeValue这两个属性似乎都是节点的 innerHTML。
nodeValue: The value of this node, depending on its type
textContent: This attribute returns the text content of this node and its descendants.
这两个属性有什么区别?什么时候使用一个而不是另一个是合适的?
最佳答案
我终于也想知道区别,所以我深入研究了 source并找到了答案;在大多数情况下,不会有明显的区别,但您应该注意一些边缘情况。
->nodeValue
和 ->textContent
对于以下类(节点类型)是相同的:
->nodeValue
属性为以下类(节点类型)生成 NULL
:
->textContent
属性对于以下类不存在:
DOMNameSpaceNode
(未记录,但可以通过//namespace:*
选择器找到)
->nodeValue
属性对于以下类不存在:
另请参阅:dom_node_node_value_read()
和 dom_node_text_content_read()
关于PHP DOM textContent 与 nodeValue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12380919/