PHP DOM: get Nodevalue without descendant nodes

I am using php dom function nodeValueto extract text content. But it also returns the values ​​of the descendants:

<example>
<inhalt>123<more>45</more></inhalt>
</example>

return for inhalt12345 and 123, as I prefer. I know that it makes no sense and is not very good to have text inside inhalt, but how do I check that there is no text in inhalt, for example hasNodeValue?

+3
source share
1 answer

As Phil mentioned, the text is also organized in nodes. Therefore, your node inhalt has two children: the text node ("123") and another node element that also has the text node ("45").

, , , , , ( DOMText, ).

, " ", .

http://www.php.net/manual/en/class.domtext.php

+3

Source: https://habr.com/ru/post/1774838/


All Articles