1

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"}
2
  • 1
    What is the PHP code that results in the above output? Commented Dec 13, 2016 at 20:27
  • 1
    It looks like its returning json, not xml. Try using json_decode to parse instead. Commented Dec 13, 2016 at 21:46

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

False, if you don't pass second argument in json_decode function you can't access as array but as an object
Ah ok. That gets me my array I wanted in the first place. Thank you! I haven't done anything with JavaScript or JSON, time to read up a bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.