title: Using DOMDocument & loadHTML in PHP to find out the class of a tag
body: <p>I want to get all LI tags that are inside OL tags which have the "bananas" class, so for example if the HTML looks like:</p>
  
  <pre><code>&lt;ol class="pluots plums grapes"&gt;
      &lt;li&gt;back to the future 2&lt;/li&gt;
      &lt;li&gt;lemon bars&lt;/li&gt;
  &lt;/ol&gt;
  
  &lt;ol class="walnuts bananas cornbread"&gt;
      &lt;li&gt;mustard&lt;/li&gt;
      &lt;li&gt;ketchup&lt;/li&gt;
  &lt;/ol&gt;
  </code></pre>
  
  <p>I want to be able to get mustard &amp; ketchup only.</p>
  
  <p>So this here:</p>
  
  <pre><code>@$doc-&gt;loadHTML($html);
  $ols = $doc-&gt;getElementsByTagName('ol');
    foreach ($ols as $ol) {
       echo "&lt;br/&gt;". $ol-&gt;nodeName. ": ";
       $nodes = $ol-&gt;childNodes;
       foreach ($nodes as $node) {
            echo $node-&gt;nodeValue. "\n";
      }
  }
  </code></pre>
  
  <p>will get me all of the LI's but I want to get only the ones from the OL that has "bananas" class?</p>
  
  <p>I can get the class names kind of clumsily by doing this:</p>
  
  <pre><code>foreach ($ol-&gt;attributes as $attr) {
      $value = $attr-&gt;nodeValue;
  }
  </code></pre>
  
  <p>I just want to be able to call the class for an OL so I figured it would be something like:</p>
  
  <pre><code>$class=$ol-&gt;attributes-&gt;[????]-&gt;nodeValue to get the class but I can't seem to figure it out.
  </code></pre>
  
  <p>I need to be able to select by class because sometimes these OLs will be in different order.</p>