Search code examples
phparraysindexingsimple-html-domvariable-length

Element length and index with simple html dom


I'm using Simple HTML DOM to get a certain element like this:

foreach($html->find('img') as $d) { 
 echo $d->outertext;
}

This will echo all the images. Let's say for example I only need image with index (meaning relative to all images) number 3,7,14 and > 15. Is there a way to do something this complicated?


Solution

  • find returns an array so just use the index

    $imgs =$html->find('img');
    
    $imgs[3];
    $imgs[7];
    $imgs[14];
    
    for($i=15;$i<count($imgs);$i++){
      $imgs[$i];
    }