使用具有 2 个属性的 Simple_Html_Dom Find

发布于 2024-09-07 18:28:03 字数 192 浏览 4 评论 0原文

有谁知道我如何使用 simple_html_dom 的 find 函数来查找指定 2 个属性而不是 1 个属性的 html 元素?

就像现在我正在使用

$area2 = $html->find('td[width="450"]');

但是说我还想指定对象的高度等

我该怎么做?

谢谢!

Does anyone know how i could use simple_html_dom's find function to find an html element specifying 2 attributes instead of 1?

Like right now I was using

$area2 = $html->find('td[width="450"]');

but say I want to also specify the height for the object, etc

How could I do it?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平定天下 2024-09-14 18:28:03

我希望 $html->find('td[width=450][height=450]'); 能够工作,但显然不行。

这有效:

foreach ($html->find("td[width=100]") as $td) {
    $td_html = str_get_html($td->outertext);
    foreach ($td_html->find("td[height=100]") as $td) {
        print "$td\n";
    }
}

这也是如此:

function height_filter($x) {
    return isset($x->height) && $x->height == "100";
}

foreach (array_filter($html->find("td[width=100]"),"height_filter") as $td) {
    print "$td\n";
}

I was hoping that $html->find('td[width=450][height=450]'); would work, but apparently not.

This works:

foreach ($html->find("td[width=100]") as $td) {
    $td_html = str_get_html($td->outertext);
    foreach ($td_html->find("td[height=100]") as $td) {
        print "$td\n";
    }
}

And so does this:

function height_filter($x) {
    return isset($x->height) && $x->height == "100";
}

foreach (array_filter($html->find("td[width=100]"),"height_filter") as $td) {
    print "$td\n";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文