普通网友 2013-05-15 00:46
浏览 39
已采纳

减少刮刮日期和按日分组?

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.

  • 写回答

1条回答 默认 最新

  • dtwxmn8741 2013-05-15 01:09
    关注

    This should do it:

    if ( !isset($lastDate) || $Date !== $lastDate ) {
        echo $Date.'<br>';
        echo $Time.' - '.$HomeTeam.' v '.$AwayTeam.'<br>';
        $lastDate = $Date;
    } else {
        echo $Time.' - '.$HomeTeam.' v '.$AwayTeam.'<br>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c