I\'m trying to parse an html file.
The idea is to fetch the span\'s with title
and desc
classes and to fetch their information in each div that
Instead of doing the second query try textContent
foreach ($arts as $art) {
echo $art->textContent;
}
textContent
returns the text content of this node and its descendants.
As an alternative, change the XPath to
$expression="//div[@class='thebest']/span[@class='title' or @class='desc']";
$arts = $xpath->query($expression);
foreach ($arts as $art) {
echo $art->nodeValue;
}
That would fetch the span children of the divs with a class thebest having a class of title or desc.