0
$xml_data = simplexml_load_file('demo.xml');
foreach ($xml_data->Game as $game) {
$t = $game['Time'];
$odds = $game->xpath('SportsBook[@Name="3Dimes"]/Odds');
echo 'Time: ' . $t . ' LineType: ' . $odds[0]->attributes()['LineType']
. ' LastUpdated: ' . $odds[0]->attributes()['LastUpdated'] . PHP_EOL;
}
demo.xml從XML提取值與特定的遊戲時間
<?xml version="1.0" encoding="utf-8"?>
<GameOdds SportsCode="MLB">
<Game Code="121" Date="08/25/2017" Time="1:45 PM" HomeBoardNumber="11"
Home="home" RoadBoardNumber="951" Road="Road" Note="">
<SportsBook ID="5" Name="5Dimes">
<Odds LineType="2" LastUpdated="10" />
</SportsBook>
<SportsBook ID="5" Name="3Dimes">
<Odds LineType="3" LastUpdated="20" />
</SportsBook> </Game>
<Game Code="122" Date="07/02/2017" Time="1:45 PM" HomeBoardNumber="11" Home="home" RoadBoardNumber="931" Road="Road" Note="">
<SportsBook ID="2" Name="5Dimes">
<Odds LineType="2" LastUpdated="10" />
</SportsBook>
<SportsBook ID="6" Name="3Dimes">
<Odds LineType="3" LastUpdated="30" />
</SportsBook>
</Game>
<Game Code="121" Date="08/25/2017" Time="1:45 PM" HomeBoardNumber="11" Home="home" RoadBoardNumber="951" Road="Road" Note="">
<SportsBook ID="5" Name="5Dimes">
<Odds LineType="2" LastUpdated="10" />
</SportsBook>
<SportsBook ID="5" Name="3Dimes">
<Odds LineType="3" LastUpdated="30" />
</SportsBook> </Game>
<Game Code="121" Date="08/31/2017" Time="1:45 PM" HomeBoardNumber="11" Home="home" RoadBoardNumber="951" Road="Road" Note="">
<SportsBook ID="5" Name="5Dimes">
<Odds LineType="2" LastUpdated="10" />
</SportsBook>
<SportsBook ID="5" Name="3Dimes">
<Odds LineType="3" LastUpdated="20" />
</SportsBook> </Game>
<Game Code="121" Date="08/25/2017" Time="1:45 PM" HomeBoardNumber="11" Home="home" RoadBoardNumber="951" Road="Road" Note="">
<SportsBook ID="5" Name="5Dimes">
<Odds LineType="2" LastUpdated="10" />
</SportsBook>
<SportsBook ID="5" Name="3Dimes">
<Odds LineType="3" LastUpdated="20" />
</SportsBook> </Game>
</GameOdds>
更新了我的問題,現在我想獲取只有GAME日期=「2017年8月25日」而且只能取2場比賽中只。 結果會是這樣
時間:1:45 PM 線型:2 LASTUPDATED:10
時間:1:45 PM 線型:2 LASTUPDATED:10
提前致謝。
感謝您的幫助! – Asher