Simple HTML Dom Strange Behaviour with Previous Sibling

35 Views Asked by At

I am scraping this URL enter link description herefor cricket fixtures. The project is to push all the content into an array so I can reformat for various projects including publishing to images for social media and a digital display board in the club house.

The HTML div for the fixture date prefixes multiple fixtures, so I have used ->prev_Sibling() to obtain;

include('simple_html_dom.php');
$fixtures = array();
$html = str_get_html($file_contents);
foreach($html->find('div.match-tbc div.card-table') as $card){
  $prev = $card->prev_Sibling();
  $prev = $prev->innertext;
  $fixtures[] = $prev;
  echo $prev;
  echo $card;
 }

The problem I am having is that when I push $fixtures[] = $prev; to an array, the content isn't just the date from the site as I would expect, it grabs all the data from the $table fixtures as well.

I have tried $prev->plaintext; and $prev->innertext; and still I cannot obtain just the date.

Array Output

This is a snapshot of the HTML;

enter image description here

0

There are 0 best solutions below