Reputation: 1024
I have the code below:
SimpleXMLElement Object(
[@attributes] => Array(
[id] => 542
[url] => http://google.pl
[price] => 19.29
[avail] => 1
[set] => 0
)
)
How can I get access to id with PHP?
Upvotes: 0
Views: 217
Reputation: 61
function xml_attribute($object, $attribute)
{
if(isset($object[$attribute]))
return (string) $object[$attribute];
}
print xml_attribute($xml, 'id'); //prints "542"
I can get the "id" like this
Upvotes: 1
Reputation: 2694
Try this
$attributes = $simpleXmlElement->attributes();
echo $id = $attributes['id'];
Upvotes: 1