simple_html_dom
库非常适合获取已知属性,但是有没有办法获取元素的所有属性列表?
例如,如果我有:
<div id="test" custom1="custom" custom2="custom">
我可以轻松获取id
:
$el = $html->find('div');
$id = $el->id;
但是,如果事先不知道 custom1
和 custom2
是否有可能得到它们?理想情况下,该解决方案将为所有属性(id
、custom1
、custom2
)生成一个 NVP
数组).
最佳答案
$el->attr
是 tag=>value
的关联数组
关于PHP 简单 HTML DOM 属性列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11830933/