0

I'm trying to make a webpage that echoes the contents of http://thegamesdb.net/api/GetGamesList.php?name=dog but in JSON format.

Right now my PHP page just has this code:

<?php 
 echo file_get_contents("http://thegamesdb.net/api/GetGamesList.php?name=dog");    
?>

I found a JSFiddle that converts XML to JSON by using Javascript:

https://jsfiddle.net/neowot/7hfyunbc/2/

...but I'm not sure how to make it compatible with my purpose.

Any help would be appreciated. Thank you.

Teli
  • 57
  • 6
  • 1
    you can find your answer here: http://stackoverflow.com/questions/8830599/php-convert-xml-to-json just two lines of code ;) – Florian Moser Feb 02 '16 at 21:43
  • 1
    Tell us about the problem you're trying to solve. It sounds more like using PHP to convert to a JSON string would be more appropriate, but you haven't told us the ultimate goal you're trying to achieve. This sounds like an example of an XY problem http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/66378#66378 – Adam Konieska Feb 02 '16 at 21:46

1 Answers1

3

This should work. The answer is taken from PHP convert XML to JSON and slightly modified

$xml_string = file_get_contents("http://thegamesdb.net/api/GetGamesList.php?name=dog");
$xml = simplexml_load_string($xml_string);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
Community
  • 1
  • 1
JTC
  • 3,344
  • 3
  • 28
  • 46