0

我使用以下内容从网站上抓取足球赛程......

// 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>';
}

这呼应....

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

这很好......但我想要这个顺序的信息......

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

知道我会怎么做吗?我知道我可以用它substr来剪掉东西,但我不知道如何按相似的日期对其进行分组。日期将始终是M d g:iA T格式,因此可能有一种比我上面使用的方式更容易和更好的方式来剪切。

感谢您的任何建议。

4

1 回答 1

1

这应该这样做:

if ( !isset($lastDate) || $Date !== $lastDate ) {
    echo $Date.'<br>';
    echo $Time.' - '.$HomeTeam.' v '.$AwayTeam.'<br>';
    $lastDate = $Date;
} else {
    echo $Time.' - '.$HomeTeam.' v '.$AwayTeam.'<br>';
}
于 2013-05-15T01:09:09.367 回答