Grzechooo

cRep API

Aug 5th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. $url = "http://api.cyberrepublik.com/citizens/".$id;
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL, $url);
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5. $file = curl_exec($ch);
  6. $xml = new SimpleXMLElement($file);
  7. if ((int)$xml->id === 0 || (string)$xml->name === "") {
  8.     /* nie ma takiego gracza */
  9. }
  10. $id = (int)$xml->id;
  11. $nick = (string)$xml->name;
  12. $exp = (int)$xml->exp;
  13. $well = (int)$xml->wellness;
  14. $bday = strtotime((string)$xml->birthday);
  15. $lvl = (int)$xml->level;
  16. $company = (int)$xml->company;
  17. $minfo = $xml->{'military-info'};
  18. $mrank = (int)$minfo->{'military-rank'};
  19. $dmg = (int)$minfo->{'total-dmg'};
  20. $hits = (int)$minfo->{'total-hits'};
  21. foreach ($xml->skills->military->skill as $skill) {
  22.     $skills["military"][(string)$skill->name] = (int)$skill->points;
  23. }
  24. foreach ($xml->skills->economy->skill as $skill) {
  25.     $skills["economy"][(string)$skill->name] = (int)$skill->points;
  26. }
  27. $residence = (string)$xml->residence->region->name;
  28. $residenceid = (int)$xml->residence->region->id;
  29. $country = (string)$xml->residence->country->name;
  30. $cid = (int)$xml->residence->country->id;
  31. $party = (string)$xml->politics->party;
  32. $pstatus = (string)$xml->politics->status;
  33. foreach ($xml->medals->medal as $medal) {
  34.     $medals[(string)$medal->name] = (int)$medal->amount;
  35. }
  36. /* output danych */
Advertisement
Add Comment
Please, Sign In to add comment