2

I have the following part of my xml:

<book number="AB 123" type="SCI">
  <info>
    <type code="FIC"><![CDATA[Fiction]]></status>
    <publish-time><![CDATA[20090110214000]]></publish-time>
  </info>
</book>

If I do:

echo $key->info->type;

I get nice and easy "Fiction"

BUT if I do:

echo $key->info->publish-time;

I get "0".

I thought it might have to do with this (20090110214000) being a number, but I tried various ways to extract that but with no success. When I print_r I see the 20090110214000 just fine in there but why can I not get that value (as a number or string) to be echoed or assign it to a variable?

hakre
  • 193,403
  • 52
  • 435
  • 836
Mark
  • 23
  • 2
  • See as well: [SimpleXML Reading node with a hyphenated name](http://stackoverflow.com/q/3626901/367456) – hakre Jul 08 '13 at 09:19

1 Answers1

0

What you do is $key->info->publish - time, basically a substraction of an undefined value minus an unknown constant (results in 0).

Use $key->info->{'publish-time'} to retrieve the correct value.

halfdan
  • 33,545
  • 8
  • 78
  • 87