PDA

View Full Version : Parse custom XMLs with PHP to array to Flash


boff
02-25-2008, 01:24 PM
hey people,

i want to parse any XML structure into a multidimensional array using one PHP script - can anyone point me in the right direction?

Ive dabbled with PHP and XML before, but it causes many headaches. I can create a PHP file for every different XML structure i have; but that's a big pain in the.. :o

i found this script: lastRSS (http://lastrss.webdot.cz/) , but it seems to be for standard RSS feeds

cheers

sneakyimp
02-27-2008, 01:56 AM
XML can be quite a headache if you don't use it frequently but once you get used to it, it can be quite useful. I don't use it frequently so for me it's just a big headache.

I use this Sephiroth's Serializer (http://www.sephiroth.it/test/unserializer/) class which lets you just take some elaborate PHP variable (either nested objects or multi-dimensional array) and just serialize it and return it to Flash like this:

// assume $myObject is some really fancy nested array or something
$serializedObject = serialize($myObject);
echo '&serializedObject=' . urlencode($serializedObject);


Then in Flash you just use the Serializer class to unserialize the string. He's got samples on his page.

boff
02-27-2008, 02:04 AM
oh ive actually used that before when building flash for a myspace page. what im after is PHP that can somehow detect the structure and all node names in any XML file, and push the contents to an array.

all i can find are resources that instruct me to have a custom PHP file for each XML file that needs to be read. it's not that much of a pain because im only ever dealing with 4 or 5, but i suppose it makes things easier for the future :)