DOMDocument Problem
Posted: Mon Jun 24, 2013 9:30 pm
If I have html like this that I want to parse, how do I get to the correct paragraph?
[syntax=xhtml]<div class='wrong'>
<p>Wrong</p>
<p>Wrong</p>
<p>Wrong</p>
</div>
<div class='correct'>
<p>Wrong</p>
<p>Correct</p>
<p>Wrong</p>
</div>
<div class='wrong'>
<p>Wrong</p>
<p>Wrong</p>
<p>Wrong</p>
</div>[/syntax]
I can use this to get the div
[syntax=php]$doc = new DOMDocument();
$doc->loadHTML($html);
$doc = $doc->getElementsByTagName('div')->item(1);
$doc = $doc->nodeValue;
[/syntax]
but how do I reach down to the p tag?
[syntax=xhtml]<div class='wrong'>
<p>Wrong</p>
<p>Wrong</p>
<p>Wrong</p>
</div>
<div class='correct'>
<p>Wrong</p>
<p>Correct</p>
<p>Wrong</p>
</div>
<div class='wrong'>
<p>Wrong</p>
<p>Wrong</p>
<p>Wrong</p>
</div>[/syntax]
I can use this to get the div
[syntax=php]$doc = new DOMDocument();
$doc->loadHTML($html);
$doc = $doc->getElementsByTagName('div')->item(1);
$doc = $doc->nodeValue;
[/syntax]
but how do I reach down to the p tag?