Ask about a PHP problem here.
-
FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Post
by FrederickGeek8 »
If I have html like this that I want to parse, how do I get to the correct paragraph?
<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>
I can use this to get the div
$doc = new DOMDocument();
$doc->loadHTML($html);
$doc = $doc->getElementsByTagName('div')->item(1);
$doc = $doc->nodeValue;
but how do I reach down to the p tag?
-
Helx
- Posts: 350
- Joined: Thu May 17, 2012 6:45 am
- Location: Auckland, New Zealand
Post
by Helx »
I don't understand what you're problem is..
Could you please elaborate?
-
FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Post
by FrederickGeek8 »
I want to do something like this (this isnt a valid statement but you should get the right idea)
$doc = $doc->getElementsByTagName('div')->item(1)->getElementsbyTagName('p')->item(1);