0

I have following XML

SimpleXMLElement Object
(
   [active-until] => 2015-03-16T13:45:32Z
   [billing-first-name] => rriiggiidd
   [billing-last-name] => smith
   [created-at] => 2014-03-16T13:45:32Z
   [customer-id] => 50
   [eligible-for-free-trial] => false
   [email] => rigids.php2@gmail.com
   [expired-at] => SimpleXMLElement Object
       (
           [@attributes] => Array
                 (
                     [type] => datetime
                     [nil] => true
                  )

       )
)

I want to fetch value for customer-id and email I am using the code as echo $xml->email;

It is working for me but when i used same for customer-id like echo $xml->customer-id;

It didn't worked(may be because it contains (-))

Can anyone please suggest how to access value if it has hyphen (-).

Any help is really appreciated.

user930026
  • 1,647
  • 5
  • 34
  • 59
  • possible duplicate of [Hyphens in Keys of Object](http://stackoverflow.com/questions/2925044/hyphens-in-keys-of-object) – Fabio Mar 16 '14 at 13:59

1 Answers1

1

Try as following for the spaces

$object->{'object-property'};

So in your case it will be as

$xml->{'customer-id'};  

etc.

Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63