Re: XML Array

From: Date: Wed, 16 Jul 2003 16:12:15 +0000
Subject: Re: XML Array
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-155460@lists.php.net to get a copy of this message
>>>>> "Lee" == Lee Doolan <leed_25@lycos.com> writes: >>>>> "Michael" == Michael Smith <msmith@prattmuseum.org> writes: Michael> Hey, I'm looking for a function to take an XML file and Michael> turn it into a PHP array with the same structure. Lee> here's something that I found on the internet a few months Lee> back. here I am following up my own post yet again.. I forgot to include an example of use. here's a little snippet that uses xmlize(): ## probably actually should use join here. I guess I was too concerned ## about the whitespace $xData=""; while (list($k, $v)= each($xml)) { $xData .= trim($v); } ## turn the XML into an array $ary= xmlize($xData); ## split into several different arrays depending on donation amount $hofTable= $ary['patronHofTable']['#']['tableData']['0']['#']['hofTableEntry']; $platinumAry= $goldAry= $silverAry= $insiderAry= array(); if (!isset($hofTable['0']['#']['text'])) { foreach($hofTable as $hofkey => $hofVal) { $entry= $hofVal['#']['Data']['0']['#']; if ($entry > 999) { $platinumAry[]= $hofVal; } else if ($entry > 499) { $goldAry[]= $hofVal; } else if ($entry > 99) { $silverAry[]= $hofVal; } else { $insiderAry[]= $hofVal; } } }

« previous php.general (#155460) next »