Converting XML file elements into a PHP array

liamp47 picture liamp47 · May 4, 2013 · Viewed 28.9k times · Source

I'm trying to convert a Steam group members list XML file into an array by using Php. The XML file is: http://steamcommunity.com/groups/starhawk/memberslistxml/?xml=1.xml

The elements are the member's steam IDs, such as 76561198000264284

How can I go about doing this?

Edit: So far I've used something like this:

$array = json_decode(json_encode((array)simplexml_load_string($xml)),1); 

It outputs the first few elements, not ones specifically from

Answer

Kartik picture Kartik · May 4, 2013

This should return the fully accessible array:

$get = file_get_contents('http://steamcommunity.com/groups/starhawk/memberslistxml/?xml=1.xml');
$arr = simplexml_load_string($get);
print_r($arr);

You can now access items like this:

echo $arr->groupID64;
echo $arr->members->steamID64; 

Edit: To parse the streamID, you can do a for loop

$ids = $arr->members->steamID64;
foreach($ids as $id) {
    echo $id;
}