To do development, given that the post message is an XML packet, the data obtained through SimpleXMLElement object is not well manipulated and needs to be converted to a normal array.
Online find a lot of methods are not ideal, found through Json_decode and Json_encode can transform, so share to everyone.
$postStr=<xml> <tousername><! [cdata[touser]]></tousername> <fromusername><! [cdata[fromuser]]></fromusername> <CreateTime>1348831860</CreateTime> <msgtype><! [cdata[text]]></msgtype> <content><! [Cdata[this is a test]]></content> <MsgId>1234567890123456</MsgId> </xml>‘;$POSTOBJ=simplexml_load_string($postStr, ' SimpleXMLElement ',libxml_nocdata);$jsonStr= Json_encode ($POSTOBJ);$jsonArray= Json_decode ($jsonStr,true);Print_r($jsonArray);
The output is:
Array ( = = Touser= fromuser = 1348831860 = text = = This is a test= 1234567890123456)
It's a lot easier to do that.
Convert an SimpleXMLElement object array into a normal array in PHP