Re: To get an associative array from an XML-file?

From: Date: Thu, 02 Jan 2003 17:03:59 +0000
Subject: Re: To get an associative array from an XML-file?
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-3153@lists.php.net to get a copy of this message
Hi Fredrik, Zitat von Fredrik Johansson <Fredrik@phpportalen.net>: > This is probobly a real newbie question. But how do I get an associative > PHP-array from an XML-file? I have been looking at XML_Tree but it > confuses me. It doesen't have to be an array, but i'm going to read > config-values and need to have the config.xml in som kind of variable-form. some time ago I had to do the same. What I did was using the xml_parse_into_struct() function to have PHP create an array of the XML file. The real nasty work is restructuring this array into an associative array the way you need it, as you probably want to have something like <person> <firstname>Fredrik</firstname> <lastname>Johansson</lastname> <person> transformed into $foobar["firstname"] = "Fredrick", $foobar["lastname"] = "Johansson", etc. There are some examples for doing this restructuring on the PHP homepage (scroll down at the function docs for parse_into_struct()). I believe your question was kind of OT though ;-) Regards, Emre -- Emre Bastuz info@emre.de http://www.emre.de UIN: 561260 PGP Key ID: 0xAFAC77FD

« previous php.pear.general (#3153) next »