says, I am possible
By: padya
25 Jul 2011
It is really simple to access attributes using array form. However, you must convert them to strings or ints if you plan on passing the values to functions.
[$xml] = SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 55555
[text] => "hello world" )
)
Then using a function
<?php
function xml_attribute($object, $attribute)
{
if(isset($object[$attribute]))
return (string) $object[$attribute];
}
?>
I can get the "id" like this
?>
You can simply breakdown into more simpler and easier by simply writing
<?php
print (string) $xml['id'];
?>
No Responses yet to Access/Use SimpleXMLElement::attributes
Post new comment