Php 删掉了那些删减的日期,然后按天分组?

Php 删掉了那些删减的日期,然后按天分组?,php,loops,simple-html-dom,Php,Loops,Simple Html Dom,我使用以下工具从一个网站上刮下足球固定装置 // 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

我使用以下工具从一个网站上刮下足球固定装置

// 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
  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
来剪切内容,但我不知道如何按相似的日期进行分组。日期总是
mdg:iat
格式,因此可能有一种比我上面使用的方式更简单、更好的剪切方式

谢谢您的建议。

这应该可以做到:

if ( !isset($lastDate) || $Date !== $lastDate ) {
    echo $Date.'<br>';
    echo $Time.' - '.$HomeTeam.' v '.$AwayTeam.'<br>';
    $lastDate = $Date;
} else {
    echo $Time.' - '.$HomeTeam.' v '.$AwayTeam.'<br>';
}
if(!isset($lastDate)| |$Date!==lastDate){
回显$Date。“
”; 回声$Time.'-'.$HomeTeam.'v'.$AwayTeam.'; $lastDate=$Date; }否则{ 回声$Time.'-'.$HomeTeam.'v'.$AwayTeam.'; }
如果结果已经排序,如果您还没有回显
$Date
(因此将回显的日期存储在某处),则只回显
$Date
。如果结果没有排序,请构建一个数组,如
$results[$Date][]=$restofyourstring
,并在末尾循环这些数组。@wriken结果是按日期按时间顺序排序的,但我不知道如何让代码知道多个日期是否相同,然后将它们分组在一起。明白了吗?很好用。非常感谢。
if ( !isset($lastDate) || $Date !== $lastDate ) {
    echo $Date.'<br>';
    echo $Time.' - '.$HomeTeam.' v '.$AwayTeam.'<br>';
    $lastDate = $Date;
} else {
    echo $Time.' - '.$HomeTeam.' v '.$AwayTeam.'<br>';
}