I have a page full of elements Im trying to parse. I want class1 and class2 as seperate text. However, class 2 exists inside class1. So if I do textContent, it retrieves all the text.
Heres the structure...
<div class='class1'>
Name <br/> <span class='class2'>Other Name</span>
</div>
If I do this...
$dom = new DOMDocument();
$dom->loadHTMLFile($url);
$finder = new DomXPath($dom);
$classname="class2";
$nodes = $finder->query("//*[contains(@class, '$classname')]");
foreach($nodes as $n){
echo $n->textContent;
}
I can get the class2 elemtn just fine. But if I do the same for class1. I get the textContent of class1 which also includes the contents of class2.
How can I extract these seperately?