简体   繁体   中英

PHP Simple HTML DOM list of attributes

The simple_html_dom library is great for getting known attributes, but is there a way to get a list of all the attributes for an element?

For example, if I have:

<div id="test" custom1="custom" custom2="custom">

I can easily get the id :

$el = $html->find('div');
$id = $el->id;

But, is it possible to get custom1 and custom2 if they are not known ahead of time? Ideally, the solution would produce an array of the NVP 's for all attributes ( id , custom1 , custom2 ).

$el->attrtag=>value s的关联数组

You can use get_object_vars to get an associative array, and then loop over them.

$attrs = get_object_vars($el);

foreach($attrs as $key=>$value) {
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM