【发布时间】:2013-04-24 23:20:58
【问题描述】:
我知道这个问题的答案非常简单,但这是我似乎无法使用 google/SO 解决的问题之一,因为它处理的字符很难搜索。我正在使用 php 从 rest api 获取 xml。我使用了 simple_xml_load_string($string) 现在当我 print_r 我得到这个:
SimpleXMLElement Object
(
[Seaports] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Id] => 8675309
[Name] => CHORIZON WIRELUSS
)
[Statistics] => SimpleXMLElement Object
(
[Clicks] => 194
)
等
假设我想要
$xml->Seaports[0]->@attributes['Id']
echo $xml->Seaports[0]->@attributes['Id'];
给我一个语法错误和
echo $xml->Seaports[0]->attributes['Id'];
我做错了什么?
【问题讨论】:
-
你是怎么做到的?另外,添加时会出现什么错误?
-
哦该死的,刚刚找到这个stackoverflow.com/questions/7523044/…
-
@p.g.可以发生。使用常见的东西(例如 simplexml)更好地搜索受骗者,通常较旧的答案质量更好。我很少添加好的新内容,我什至越来越频繁地扩展旧的问答。