codec101
codec101

Reputation: 13

PHP not getting XML data from URL correctly

Simply put, I'm trying to use PHP to get data from an URL and display a list.

Background: I have an application running on one computer that uses APIs and it's own built-in webserver. (This is not my application.) From any computer on my network I can type in the URL (http://internal-ip-address:port/api/play/getSequences) and I get the data I expect displayed in a nice XML format.

I am trying to get the PHP script on my webserver on my home server to pull that info and make a list.

I can call that URL from a curl request or from get_file_contents and I get the data but it is not in the XML format as expected and I can not parse it as XML.

Output is

[{"Name":"SomeName","FileName":"SomeFile"},
 {"Name":"SomeOtherName","FileName":"SomeOtherFile"}

Upvotes: 1

Views: 50

Answers (1)

Pipe
Pipe

Reputation: 2424

This is not XML is JSON, so you can save content into a $string and do:

$data = json_decode($string, true);

Then you can access as:

echo $data[0]["Name"]; //SomeName

Upvotes: 1

Related Questions