NaughtySquid
NaughtySquid

Reputation: 2097

Dealing with xml file and php

currently trying to parse this file: https://linux.gamesrepublic.com/xml/catalog?currency=usd&count=all&mode=OnlyPromotions

I am currently bringing it in like this:

$xml = simplexml_load_string(file_get_contents($url));

foreach ($xml->group->o as $game)
{

That correctly gets the array of information into $game, but my problem is how to access the "platform" tags inside the "platforms" tag, which is also inside the "attrs" tag (so many levels!).

How can I easily get access to that? I was thinking like this to check if say Linux is a platform:

if (in_array('Linux', $game->attrs->platforms->platform))
{
    echo 'Linux: Yes';
}

That just isn't right though it seems.

Upvotes: 0

Views: 30

Answers (1)

Rick Slinkman
Rick Slinkman

Reputation: 663

The simplexml_load_string function SimpleXMLElement to you. This type has a function children() that returns an array of all child elements. These children are also of type SimpleXMLElement.

Read more: http://php.net/manual/en/class.simplexmlelement.php

Upvotes: 1

Related Questions