PHP:简单的 HTML DOM 解析器 - find() 中有多个属性? [英] PHP: Simple HTML DOM Parser - multiple attributes in find()?

查看:47
本文介绍了PHP:简单的 HTML DOM 解析器 - find() 中有多个属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Simple HTML DOM Parser,但不知道如何获取具有 2 个或更多匹配属性的元素.

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

遗憾的是,要获得前 2 个 div,这不起作用:

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]");

有可能吗?

推荐答案

您可以通过调用:

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

有关详细信息,参见手册如何查找 HTML 元素 -> 高级".

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

这篇关于PHP:简单的 HTML DOM 解析器 - find() 中有多个属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆