xml - How do we acces simpleXMLElement object in php -
simplexmlelement object ( [0] => cem ) there simplexmlelement object this. tried accessing $object->0 , $object->{0}. giving php error. how access out changing format.
from print_r output might not obvious:
simplexmlelement object ( [0] => cem ) this single xml element containing string cem, example:
<xml>cem</xml> you obtain value casting string (see basic simplexml usagedocs):
(string) $object; when have simplexmlelement object , you're unsure represents, it's easier use echo $object->asxml(); output xml , analyze using print_r alone because these elements have lot of magic need know read print_r output properly.
an example above:
<?php $object = new simplexmlelement('<xml>cem</xml>'); print_r($object); echo "\n", $object->asxml(), "\n"; echo 'content: ', $object, "\n"; // echo cast string automatically output:
simplexmlelement object ( [0] => cem ) <?xml version="1.0"?> <xml>cem</xml> content: cem
Comments
Post a Comment