-5

我正在尝试通过 xml 从 Steam 获取来自用户通过 php 的归档列表。

http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=212910&key=xxxxx&steamid=xxxxx&l=german&format=xml

xml=

-<playerstats>
 <success>true</success>
  <steamID>76561198070477917</steamID>
  <gameName>Call of Duty: Black Ops II - Zombies</gameName>
 -<achievements>
   -<achievement>
      <apiname>ZM_TRANSIT_SIDEQUEST</apiname>
      <achieved>1</achieved>
      <name>Der Turm von Gebrabbel</name>
      <description>Hören Sie in TranZit auf die Stimmen.</description>
    </achievement>
   -<achievement>
      <apiname>ZM_DONT_FIRE_UNTIL_YOU_SEE</apiname>
      <achieved>0</achieved>
      <name>Erst bei Sichtkontakt feuern</name>
      <description>Öffnen Sie in TranZit sämtliche Türen, ohne in Brand gesteckt zu werden.</description>
    </achievement>

我尝试仅列出在“1”上具有“已实现”值的元素。我在所有事情上都取得了成功,但现在我试图只获得具有已实现 1 的特殊元素——

PHP=

    $url11= 'http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=' . $dasgame . '&key=' . $steam_api . '&steamid=' . $username . '&l=german&format=xml';
    $data11 = file_get_contents($url11);
    $xml11 = simplexml_load_string($data11);
    $daslade = $xml11->success;
    $daswert = "true";
    if($daslade == $daswert) { 

    foreach ($xml11->achievements->children() as $items){

    $dasladen = $items->apiname;
    print $xml8->availableGameStats->achievements->achievement->$dasladen;                      
    //print htmlentities($items->name);print "--->";
    print htmlentities($items->description);print "</br>"; };
 } else { 
print "Für dieses Spiel sind keine Errungenschaften vorhanden."; }
 };

提前谢谢你有问题所以有空问我

4

1 回答 1

0

如果您想跳过所有没有achieved值为 的元素的元素1,您可以使用该continue语句跳过其余的处理并移动到列表中的下一项。

foreach ( $xml11->achievements->children() as $items ){
    if ( $items->achieved != 1 ) continue;
    // ... rest of your code
}
于 2014-05-31T20:07:33.473 回答