1

I have html like this :

<h3><span itemprop="name">ABC</span> XYZ</h3>

I used xpath but it only get the text in span tag (ABC) , now i want to get text after span . Ex: I want to get XYZ

Here is my code :

string = mb_convert_encoding($string, 'HTML-ENTITIES', "UTF-8");
    $dom = new DOMDocument();
    @$dom->loadHTML($string);
    $xpath = new DOMXPath( $dom );
    $nodelist = $xpath->query( "//h3/span[@itemprop='name']/text()" );     
    return $nodelist->item(0)->nodeValue;

And ressult is : ABC

1 Answer 1

4

Try:

//h3/span[@itemprop='name']/following-sibling::text()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.