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->attr
是tag=>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.