I use the following to scrape soccer fixtures from a site...
// Retrieve the URL
$url = 'http://fantasy.mlssoccer.com/fixtures/';
$html = @file_get_html($url);
//cuts out just the table
$FullFixTable = $html->find('table[class=ismFixtureTable]',0);
// Find all results and break them up into pieces
foreach($FullFixTable->find('tr[class=ismFixture]') as $ResultsToCutOut)
{
$GameDate = $ResultsToCutOut->find('td',0)->innertext;
$Date = substr($GameDate, 0, 6);
$Time = substr(substr($GameDate, 0, -4), (strlen(substr($GameDate, 0, -6))-5)*-1);
$HomeTeam = $ResultsToCutOut->find('td',1)->innertext;
$AwayTeam = $ResultsToCutOut->find('td',5)->innertext;
echo $Date.' '.$Time.' '.$HomeTeam.' v '.$AwayTeam.'<br>';
}
This echoes....
May 15 7:30PM Philadelphia Union v Los Angeles Galaxy
May 18 5:00PM Toronto FC v Columbus Crew
May 18 7:00PM Vancouver Whitecaps v Portland Timbers
May 18 7:30PM Philadelphia Union v Chicago Fire
May 18 8:30PM Houston Dynamo v New England Revolution
May 18 10:30PM San Jose Earthquakes v Colorado Rapids
May 18 10:30PM Seattle Sounders FC v FC Dallas
May 19 1:00PM New York Red Bulls v Los Angeles Galaxy
May 19 5:00PM D.C. United v Sporting Kansas City
May 19 10:30PM Chivas USA v Real Salt Lake
Which is fine... but I want the information in this order....
May 15
7:30PM Philadelphia Union v Los Angeles Galaxy
May 18
5:00PM Toronto FC v Columbus Crew
7:00PM Vancouver Whitecaps v Portland Timbers
7:30PM Philadelphia Union v Chicago Fire
8:30PM Houston Dynamo v New England Revolution
10:30PM San Jose Earthquakes v Colorado Rapids
10:30PM Seattle Sounders FC v FC Dallas
May 19
1:00PM New York Red Bulls v Los Angeles Galaxy
5:00PM D.C. United v Sporting Kansas City
10:30PM Chivas USA v Real Salt Lake
Any idea how I would do that? I know I can use substr
to cut stuff out, but I have no idea how to group it by similar date. Dates will always be M d g:iA T
format, so there's probably a far easier and better way to cut out than the way I used above.
Thanks for any suggestions.