dianeinflorida
dianeinflorida

Reputation: 53

Simple HTML DOM Parser and a for each loop

I am using PHPCRAWL and SIMPLEHTMLDOMPARSER to get some data from a public website. It has taken me forever to figure this out, but now I have another question that I am lost on.
Using the code below I can get the $first item for each page, but here is the catch there are multiple $first (maybe 2 or 3). I am trying to catch all $firsts for a given page as one variable, lets say $allfirst . Any guidance, advice is greatly appreciated.

 $html=file_get_html("$DocInfo->url");
    foreach ($html->find('div[id=sidebar] h4') as $e) {
      $first = $e->next_sibling();
     echo $first;
  }

Upvotes: 0

Views: 4602

Answers (1)

Moe Tsao
Moe Tsao

Reputation: 1054

You need to make $first an array.

$html=file_get_html("$DocInfo->url");
$first=array();
foreach ($html->find('div[id=sidebar] h4') as $e) {
  $first[] = $e->next_sibling();

}
 print_r ($first);

Edit =====

The print_r($first) should be outside the loop.

Upvotes: 1

Related Questions