Fix XPath query to extract inner text div
I am using XPath to query into an HTML document where there is the following div:
<div class="h1">2008 Honda Accord Coupe<small> — Wuse II</small></div> I wanted to get only the internal text <div class="h1">2008 Honda Accord Coupe and not include the <small>inner text</small>
I am making the following XPath request: //div[@class='h1'] , which definitely returns the integer <div>...</div> node.
How can I get only a part without <small>...</small>
thanks
You can do this:
$name = trim($xpath->query('//div[@class="h1"]')->item(0)->childNodes->item(0)->nodeValue); var_dump($name);