【问题标题】:access value from SimpleXMLElement in PHP从 PHP 中的 SimpleXMLElement 访问值
【发布时间】:2014-03-16 13:56:03
【问题描述】:

我有以下 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
                  )

       )
)

我想获取 customer-idemail 的值 我使用的代码为echo $xml->email;

它对我有用,但是当我对customer-id 使用相同的echo $xml->customer-id;

不起作用(可能是因为它包含(-))

如果有连字符 (-),任何人都可以建议如何访问值。

非常感谢任何帮助。

【问题讨论】:

标签: php xml


【解决方案1】:

空格试试如下

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

所以在你的情况下,它会是

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

等等

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-23
    • 1970-01-01
    • 2012-02-03
    • 2011-02-14
    • 2013-03-27
    • 2015-01-06
    • 2015-01-04
    相关资源
    最近更新 更多