2014-01-22 51 views
0

我試圖分析此文件,該文件被命名爲Roster->播放器 - >名稱的組成有相同的元素名稱的SimpleXML解析數據

http://gamebattles.majorleaguegaming.com/ps4/call-of-duty-ghosts/team/ngx2-gaming/stats.xml

我已經成功地拉到與下面的代碼的其他領域,但正如你可以看到,如果你運行代碼,它只會顯示第26行的第一個球員的名字。有人可以幫助我瞭解如何顯示其他人?

謝謝!

<?php 
$url="http://gamebattles.majorleaguegaming.com/ps4/call-of-duty-ghosts/team/ngx2-gaming/stats.xml"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_URL, $url); // get the url contents 
$data = curl_exec($ch); // execute curl request 
curl_close($ch); 
$xml = simplexml_load_string($data); 
?> 
<html> 
<head> 
<title>Stats</title> 
</head> 
<body> 
Game: <?php echo $xml->arena; ?><br/> 
Platform: <?php echo $xml->platform; ?><br/> 
Matches Played: <?php echo $xml->alltimeStats->matchesPlayed; ?><br/> 
Shutotus: <?php echo $xml->currentStats->shutouts; ?><br/> 
Level: <?php echo $xml->currentStats->level; ?><br/> 
Current Streak: <?php echo $xml->currentStats->streak; ?><br/> 
Ladder Place: <?php echo $xml->currentStats->place; ?><br/> 
TeamName: <?php echo $xml->name; ?><br/> 
Wins: <?php echo $xml->currentStats->wins; ?><br/> 
Losses: <?php echo $xml->currentStats->losses; ?><br/> 
Roster: <?php echo $xml->roster->player->name; ?><br/> 
</body> 
</html> 

回答

1

既然有XML文檔中的姐弟幾個要素,你必須遍歷它們,就像您的數組:

<?php 
foreach($xml->roster->player as $player) { 
    echo $player->name; ?><br/><?php 
} 
?> 
+0

謝謝你,這個偉大的工程! – KJThaDon

相關問題