title: How can I retrieve infos from PHP DOMElement?
body: <p>I'm working on a function that gets the whole content of the style.css file, and returns only the CSS rules that needed by the currently viewed page (it will be cached too, so the function only runs when the page was changed).</p>
  
  <p>My problem is with parsing the DOM (I'm never doing it before with PHP DOM). I have the following function, but $element->tagname returns NULL. I also want to check the element's "class" attribute, but I'm stuck here.</p>
  
  <pre><code>function get_rules($html) {
      $arr = array();
      $dom = new DOMDocument();
      $dom-&gt;loadHTML($html);
      foreach($dom-&gt;getElementsByTagName('*') as $element ){
          $arr[sizeof($arr)] = $element-&gt;tagname;
      }
      return array_unique($arr);
  }
  </code></pre>
  
  <p>What can I do? How can I get all of the DOM elements tag name, and class from HTML?</p>