Answer the question
In order to leave comments, you need to log in
How to get and immediately merge the next (after the current) elements?
Hello!
There is a markup:
<div class="abc">
<span class="foo">Hello</span>
<span class="bar">World</span>
<span class="baz">by</span>
</div>
span.foo
How to get the text content of the next two ( span.bar
and span.baz
)
by pushing from the element . div/span[@class="foo"]//concat(following-sibling::*[1], following-sibling::*[2])
concat()
. When I wrap it in square brackets, it doesn't work either.
Answer the question
In order to leave comments, you need to log in
<?php
$dom = new DOMDocument();
$dom->loadXML('
<div class="abc">
<span class="foo">Hello</span>
<span class="bar">World</span>
<span class="baz">by</span>
</div>');
$xpath = new DOMXPath($dom);
$result = $xpath->evaluate('concat(/div/span[@class="foo"]/following-sibling::*[1], " ", /div/span[@class="foo"]/following-sibling::*[2])');
var_dump($result);
string 'World by' (length=8)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question