Answer the question
In order to leave comments, you need to log in
XPath: how to find a node?
Good afternoon!
How to find direct descendants of an element (including text nodes containing inline tags) of an element?
An example example was:
<div id="orion">
Lorem ipsum <i>dolor</i> sit amet.
Lorem <b>ipsum</b> dolor sit amet.
<p>Lorem ipsum dolor sit amet.</p>
<span>Lorem ipsum dolor sit amet.</span>
</div>
<div id="orion">
<p>
Lorem ipsum <i>dolor</i> sit amet.
Lorem <b>ipsum</b> dolor sit amet.
</p>
<p>Lorem ipsum dolor sit amet.</p>
<p>
<span>Lorem ipsum dolor sit amet.</span> Lorem ipsum dolor sit <span>amet</span>.
</p>
</div>
$dom = new DOMDocument;
$dom->loadHTML( '$html' );
$xpath = new DOMXPath( $dom );
foreach ( $xpath->query( '//div/text()[i][b][span] | //div/node()' ) as $textNode ) {
echo trim( $textNode->nodeValue ), PHP_EOL;
}
text()[i][b][span]
. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question