Skip to content
Advertisement

How do I use php to access a data point within xml output coming from a url?

I am trying to access a single data point from the XML below. My goal would then be to insert into an html table. The following code has been giving me a stdClass Object and I can’t figure out how to grab a single data point.

Here is the XML:

JavaScript

And the PHP:

JavaScript

Advertisement

Answer

Actually your json functions are not doing anything at all. json_encode is the opposite of json_decode, so you can just completely omit those two lines.

The contents of the data points can be found, for example:

JavaScript

If you’re just echoing the value or using it in a string context, you don’t need __toString() since that will be implied, but beware that without this, it is really an instance of an SimpleXMLElement object, not an actual string.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement