PHP: Simple HTML DOM Parser - multiple attributes in find()?

坚强是说给别人听的谎言 提交于 2020-01-05 03:00:28

问题


I'm using Simple HTML DOM Parser but can't figure out how to get elements that have 2 or more matching attributes.

Sadly, to get the first 2 divs, this doesn't work:

$html = "<div title='test a' class='a' >test a</div>
         <div title='test b' class='b' >test b</div>
         <div title='test c' class='c' >test c</div>";

$htmldom = str_get_html($html);
$ab = $htmldom->find("div[class=a][class=b]");

Is it even possible?


回答1:


You can find all divs with either class a or class b by invoking:

$ab = $htmldom->find("div[class=a], div[class=b]");

For details, see manual on "How to find HTML elements -> Advanced".



来源:https://stackoverflow.com/questions/11125331/php-simple-html-dom-parser-multiple-attributes-in-find

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!