2012-07-05 44 views
0

我有一个包含对象中的@sign的数组。我不能访问
其实我解析XML到数组
print_r输出低于
无法访问包含@符号的数组对象

[link] => SimpleXMLElement Object 
         (
          [@attributes] => Array 
           (
            [type] => text/html 
            [href] => http://www.livingsocial.com/cities/1964-klang-valley-kuala-lumpur/deals/393950-2-pax-steamboat-set-2-iced-lemon-tea 
            [rel] => alternate 
           ) 

         ) 



$入门>链路>@属性 - > href
无法访问

+0

尝试$入门>链接 - > {“@属性” } – 2012-07-05 09:48:52

+0

这是不正确的语法,在XML元素的属性不能有@标志 – Gntem 2012-07-05 09:50:08

回答

1

您必须使用attributes()方法d从SimpleXMLElement对象

$entry->link->attributes(); 

获取属性如果你想获得href属性为字符串,你可以做到以下几点:

$href = $entry->link->attributes()->href->__toString(); 
+0

真棒...其工作..谢谢.. – Natasha 2012-07-05 10:22:34