简体   繁体   中英

How to check two attributes with Simple HTML DOM?

I need to get a very specific tag using Simple HTML DOM, and have to check two attributes to do this, but I'm not sure how. Right now I have this:

foreach($html->find("ul[class=someclass]") as $step1)

But within that same <ul> tag there is also an id attribute that equals, let's say, "xyz". So how can I check both? I'm assuming something like this (although it doesn't seem to work):

foreach($rt_html->find("ul[class=results_ul, id=xyz]") as $step1)

Any help?

Either of these should work:

  • ul#xyz[class=results_ul]
  • ul.results_ul[id=xyz]

I don't know that library, but if Musa's answer does not help, try this:

$myElements = array();
foreach($html->find("ul[class=someclass]") as $step1) {
    echo "found some class\n";
    if (isset($step1->id) {
       echo "found {$step->id}\n";
    }
    if (isset($step1->id) && $step1->id == 'xyz') {
        $myElements[] = $step1;
    }
}
var_dump($myElements);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM