html - How can I retrieve infos from PHP DOMElement? -


i'm working on function gets whole content of style.css file, , returns css rules needed viewed page (it cached too, function runs when page changed).

my problem parsing dom (i'm never doing before php dom). have following function, $element->tagname returns null. want check element's "class" attribute, i'm stuck here.

function get_rules($html) {     $arr = array();     $dom = new domdocument();     $dom->loadhtml($html);     foreach($dom->getelementsbytagname('*') $element ){         $arr[sizeof($arr)] = $element->tagname;     }     return array_unique($arr); } 

what can do? how can of dom elements tag name, , class html?

because tagname should undefined index because supposed tagname (camel cased).

function get_rules($html) {      $arr = array();     $dom = new domdocument();     $dom->loadhtml($html);     foreach($dom->getelementsbytagname('*') $element ){         $e = array();         $e['tagname'] = $element->tagname; // tagname not tagname         // elements attributes         foreach($element->attributes $attr) {             $attrs = array();             $attrs['name'] = $attr->nodename;             $attrs['value'] = $attr->nodevalue;             $e['attributes'][] = $attrs;         }         $arr[] = $e;     }     return $arr; } 

simple output


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -