访问SimpleXMLElement对象值
问题描述:
我有下面的代码:访问SimpleXMLElement对象值
SimpleXMLElement Object(
[@attributes] => Array(
[id] => 542
[url] => http://google.pl
[price] => 19.29
[avail] => 1
[set] => 0
)
)
我怎样才能用PHP访问ID?
答
试试这个
$attributes = $simpleXmlElement->attributes();
echo $id = $attributes['id'];
答
function xml_attribute($object, $attribute)
{
if(isset($object[$attribute]))
return (string) $object[$attribute];
}
print xml_attribute($xml, 'id'); //prints "542"
我能拿到 “身份证” 这样
的可能的复制[PHP得到的SimpleXMLElement阵列值(http://stackoverflow.com/questions/ 2751711/PHP-获得值从 - 的SimpleXMLElement阵列) –