note 75623 added to ref.xml

From: Date: Fri, 08 Jun 2007 11:29:11 +0000
Subject: note 75623 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-127294@lists.php.net to get a copy of this message
<?php /** * correction of the previous code */ /** * Converts XML into Array * * @param array $result * @param object $root * @param string $rootname */ function convert_xml2array(&$result,$root,$rootname='root'){ $n=count($root->children()); if ($n>0){ /** * start of the correction */ if (!isset($result[$rootname]['@attributes'])){ $result[$rootname]['@attributes']=array(); foreach ($root->attributes() as $atr=>$value){ $result[$rootname]['@attributes'][$atr]=(string)$value; } } /** * end of the correction */ foreach ($root->children() as $child){ $name=$child->getName(); convert_xml2array($result[$rootname][],$child,$name); } } else { $result[$rootname]= (array) $root; if (!isset($result[$rootname]['@attributes'])){ $result[$rootname]['@attributes']=array(); } } } /** * Example how to use the function convert_xml2array */ /** * Return Array from a xml string * * @param string $xml * @return array */ function get_array_fromXML($xml){ $result=array(); $doc=simplexml_load_string($xml); convert_xml2array($result,$doc); return $result['root']; } ?> ---- Server IP: 194.8.30.16 Probable Submitter: 85.241.127.7 ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- https://master.php.net/note/edit/75623 Del: integrated -- https://master.php.net/note/delete/75623/integrated Del: useless -- https://master.php.net/note/delete/75623/useless Del: bad code -- https://master.php.net/note/delete/75623/bad+code Del: spam -- https://master.php.net/note/delete/75623/spam Del: non-english -- https://master.php.net/note/delete/75623/non-english Del: in docs -- https://master.php.net/note/delete/75623/in+docs Del: other reasons-- https://master.php.net/note/delete/75623 Reject -- https://master.php.net/note/reject/75623 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127294) next »