How to target specific paragraphs within an HTML string in PHP
<p>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>

<pre><code>&lt;p&gt;blablabla.....&lt;/p&gt;
&lt;p&gt;blablabla.....&lt;/p&gt;
&lt;p&gt;blablabla.....&lt;/p&gt;
&lt;p&gt;blablabla.....&lt;/p&gt;
&lt;h3&gt;hello&lt;/h3&gt;
&lt;p&gt;blablabla.....&lt;/p&gt;
&lt;p&gt;blablabla.....&lt;/p&gt; etc etc
</code></pre>

<p>What I would like to do is loop over the nodes applying a class to each, until I hit the h3.</p>

<p>Thanks,</p>

<p>EDIT
I have so far tried:</p>

<pre><code>$dochtml = new DOMDocument();
$dochtml-&gt;loadHTML($strhtml); 

foreach ($dochtml-&gt;childNodes as $node)
{

    if($node-&gt;tagName == "p") {
    $node-&gt;setAttribute('class', 'someclass');
    } else {
    break;
}
}
</code></pre>

<p>Which simply doesn't work.</p>

<p>The HTML fragment is from a database and represents the editable portion of a page within a CMS.    </p>
