Parse XML with @params

There is XMLreceived from a third-party server:

object(SimpleXMLElement)#4 (1) {
  ["@attributes"]=>
  array(5) {
    ["message_id"]=>
    string(1) "0"
    ["message_phone"]=>
    string(11) "**********"
    ["message_parts"]=>
    string(1) "1"
    ["message_zone"]=>
    string(1) "1"
    ["message_cost"]=>
    string(3) "0,6"
  }
}

Either I’m stupid or I just don’t understand, I need to pull out the values ​​of @attributes

$xml=simplexml_load_string($str);

But how do I get to $xml->@attributes? You can’t put the sign @– you can’t.


Answer 1, authority 100%

You can use get_object_vars:

$xml=simplexml_load_string($str);
$a = get_object_vars($xml);
var_dump($a["@attributes"]);

UPDATE

In the case of PHP 5.3 it is possible without crutches:

$xml = simplexml_load_string($str);
$a = (array)$xml;
var_dump($a["@attributes"]);

Answer 2

Alternatively, work like an array: $xml[‘message_cost’] will return “0.6”.