PHP Simple HTML DOM属性列表

Mat*_*ith 3 php simple-html-dom

simple_html_dom库非常适合获取已知属性,但是有没有办法获取元素的所有属性列表?

例如,如果我有:

<div id="test" custom1="custom" custom2="custom">
Run Code Online (Sandbox Code Playgroud)

我很容易得到id:

$el = $html->find('div');
$id = $el->id;
Run Code Online (Sandbox Code Playgroud)

但是,它是否有可能获得custom1,custom2如果他们提前不知道?理想情况下,该解决方案将产生的阵列NVP的所有属性(id,custom1,custom2).

Pra*_*nth 5

$el->attr是一个相关的tag=>values 数组

  • 或者`$ el-> getAllAttributes()` (2认同)