note 97266 added to simplexmlelement.attributes

From: Date: Sun, 11 Apr 2010 02:46:05 +0000
Subject: note 97266 added to simplexmlelement.attributes
Groups: php.notes 
Request: Send a blank email to php-notes+get-168116@lists.php.net to get a copy of this message
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. <?php 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 <?php print xml_attribute($xml, 'id'); //prints "55555" ?> ---- Server IP: 64.71.164.2 Probable Submitter: 208.101.220.138 ---- Manual Page -- http://www.php.net/manual/en/simplexmlelement.attributes.php Edit -- https://master.php.net/note/edit/97266 Del: integrated -- https://master.php.net/note/delete/97266/integrated Del: useless -- https://master.php.net/note/delete/97266/useless Del: bad code -- https://master.php.net/note/delete/97266/bad+code Del: spam -- https://master.php.net/note/delete/97266/spam Del: non-english -- https://master.php.net/note/delete/97266/non-english Del: in docs -- https://master.php.net/note/delete/97266/in+docs Del: other reasons-- https://master.php.net/note/delete/97266 Reject -- https://master.php.net/note/reject/97266 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168116) next »