Hi guys
This is my example script:
$html = <<<HTML
<div class="main">
<div class="text">
Capture this text 1
</div>
<div class="date">
May 2010
</div>
</div>
<div class="main">
<div class="text">
Capture this text 2
</div>
<div class="date">
June 2010
</div>
</div>
HTML;
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$tags = $xpath->query('//div[@class="main"]');
foreach ($tags as $tag) {
print_r($tag->nodeValue."\n");
}
This will out put:
Capture this text 1 May 2010
Capture this text 2 June 2010
But I need it output:
<div class="text">
Capture this text 2
</div>
<div class="date">
June 2010
</div>
Or atleast be able to do something like this in my foreach loop:
$text = $tag->query('//div[@class="text"]')->nodeValue;
$date = $tag->query('//div[@class="date"]')->nodeValue;