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
格式,因此可能比上面使用的方式更容易和更好地切出。
感谢您的任何建议。
如果结果已经下令,除非你没有回音已是'$ Date'(所以店里回荡日期的地方)回声'$ Date'。如果结果没有排序,可以像'$ results [$ Date] [] = $ restofyourstring'一样构建一个数组,并在最后循环。 – Wrikken
@Wrikken结果按时间顺序排列,但我不知道如何让我的代码知道多个日期是否相同,然后将它们组合在一起。明白了吗? – Cully