0

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;
  }
Rodrigo Guedes
  • 1,169
  • 2
  • 13
  • 27

1 Answers1

1

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.

Moe Tsao
  • 1,054
  • 6
  • 9
  • How can I get the array $first to contain all $first for every occurance of $e->next_sibling()? – dianeinflorida Aug 31 '12 at 18:21
  • Do I need to array_merge_recursive($first)? – dianeinflorida Aug 31 '12 at 18:33
  • I have edited the code a bit, and placed the print_r outside the loop. This should make it clear that it is one single array containing the $e->next_sibling(); There should be no need for the array merge function. – Moe Tsao Aug 31 '12 at 18:52
  • Is there a way to get the array not to have the recursion and have every appearance of $e->next_sibling in the foreach ($html->find('div[id=sidebar] h4') as $e) all together? – dianeinflorida Aug 31 '12 at 19:56