A simple one for all your PHP guys out there.
I have a string which represents a portion of HTML. It looks something like this:
<p>blablabla.....</p>
<p>blablabla.....</p>
<p>blablabla.....</p>
<p>blablabla.....</p>
<h3>hello</h3>
<p>blablabla.....</p>
<p>blablabla.....</p> etc etc
What I would like to do is loop over the nodes applying a class to each, until I hit the h3.
Thanks,
EDIT
I have so far tried:
$dochtml = new DOMDocument();
$dochtml->loadHTML($strhtml);
foreach ($dochtml->childNodes as $node)
{
if($node->tagName == "p") {
$node->setAttribute('class', 'someclass');
} else {
break;
}
}
Which simply doesn’t work.
The HTML fragment is from a database and represents the editable portion of a page within a CMS.
Well: