0

I'm trying to turn a JSON file of Xbox Live data into variables that I can use in a PHP generated image. My JSON file is here: http://www.xboxgamercard.org/gamercard/test3/xbox.php

I have tried this:

$request_url = 'xbox.php';
$json = file_get_contents($request_url);
$decode = json_decode($json, true);
var_dump($decode['gamertag'][0]);

but it just returns NULL.

I would like to use the JSON as shown here:

$gamertag = $data['Gamertag'];
echo $gamertag;
Sean Mickey
  • 7,618
  • 2
  • 32
  • 58

1 Answers1

0

You need to add the full url eg:

<?php
$request_url = 'http://www.xboxgamercard.org/gamercard/test3/xbox.php';

$json = file_get_contents($request_url);
$data = json_decode($json, true);

//Example output
echo $data['gamertag']; //Crylics
echo $data['gamerscore']; //7492

/* Too access the recent_games key you will need
   to loop through it or access it like
*/
echo $data['recent_games'][1]['title']; //Call of Duty: WaW
?> 
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
  • Thank you again! Im currently passing a GET variable in the url for xbox.php and index.php that is ?gamertag=crylcs so that it changes into $request_url = 'http://www.xboxgamercard.org/gamercard/test3/xbox.php?gamertag=$gamertag'; but it doesnt seem to want to work? – user1175820 Jan 28 '12 at 23:27