jsonchiu Posted March 29, 2007 Share Posted March 29, 2007 I'm working on a php socket server for my chat room, and I need to parse some very short XML messages like this: <msg t="usr"><body a="pubMsg" u="username"><![CDATA[some message]]></body></msg> Right now I'm using a bunch of substrings (start laughing. lol), but it's very inflexible. However somehow it works... The problem arises when I try to store user variables (ignore the indents and line brakes, in reality, there will be non of them; we don't want to waste bandwidth) <msg t="usr"> <body a="updVar" u="username"> <var t="s" n="varname"><![CDATA[some variable]]></var> <var t="n" n="someNum"><![CDATA[3]]></var> </body> </msg> I have no idea how to parse those stuff from a string to an associative array... What I want is an associative array that I can access those stuff similar to this way: echo myXML['firstChild']['firstChild']['firstChild']['attributes']['t']; and it should output "s" Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/44745-xml-formatted-string-to-associative-array/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.