2016-12-28 158 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" 

我能拿到 「身份證」 這樣