2016-12-28 65 views
0

我有下面的代码:访问SimpleXMLElement对象值

SimpleXMLElement Object(
    [@attributes] => Array(
     [id] => 542 
     [url] => http://google.pl 
     [price] => 19.29 
     [avail] => 1 
     [set] => 0 
    ) 
) 

我怎样才能用PHP访问ID?

+0

的可能的复制[PHP得到的SimpleXMLElement阵列值(http://stackoverflow.com/questions/ 2751711/PHP-获得值从 - 的SimpleXMLElement阵列) –

回答

1

试试这个

$attributes = $simpleXmlElement->attributes(); 
echo $id = $attributes['id']; 
1
function xml_attribute($object, $attribute) 
{ 
    if(isset($object[$attribute])) 
     return (string) $object[$attribute]; 
} 
print xml_attribute($xml, 'id'); //prints "542" 

我能拿到 “身份证” 这样