// simplexml_load_string parses two types of XML
$ res = '
010001000249 1009011719781282 1411957176 13882524228 0096 delivrd Sichuan Suining 4 1
010001000249 1009011719781301 1411957175 18719295258 0096 delivrd guangdong Yangjiang 4 1
';
$ restat = simplexml_load_string ($ res);
Foreach ($ restat-> Children () as $ value ){
$ Arr ['restatus'] = trim ($ value-> MSG );
$ Arr ['mobile'] = trim ($ value-> mobile );
$ Arr ['taskid'] = trim ($ value-> cpmid );
$ Reply_arr [] = $ arr;
}
Print_r ($ reply_arr );
$ Re = '
200
0
010001000249 1009011719781282 1411957176 13882524228 0096 delivrd Sichuan Suining 4 1
010001000249 1009011719781301 1411957175 18719295258 0096 delivrd Guangdong Yangjiang 4 1
';
$ Restat = simplexml_load_string ($ re );
Foreach ($ restat-> Report-> Mor as $ value ){
$ Arr ['restatus'] = trim ($ value-> MSG );
$ Arr ['mobile'] = trim ($ value-> mobile );
$ Arr ['taskid'] = trim ($ value-> cpmid );
$ Reply_arr [] = $ arr;
}
Print_r ($ reply_arr );
$ Xml = '<XML name = "sendbatch" result = "1">
<Item cid = "333" SID = "333" msgid = "111" Total = "1" Price = "0.10" remain = "170.040"/>
<Item cid = "444" SID = "444" msgid = "222" Total = "1" Price = "0.10" remain = "169.940"/>
</XML> ';
$ Re = simplexml_load_string (utf8_encode ($ XML ));
If ($ re ['result'] = 1)
{
Foreach ($ re-> item as $ item)
{
$ Stat ['msgid'] = trim (string) $ item ['msgid']);
$ Stat ['Total'] = trim (string) $ item ['Total']);
$ Stat ['price'] = trim (string) $ item ['price']);
$ Stat ['remain'] = trim (string) $ item ['remain']);
$ Stat_arr [] = $ Stat;
}
Print_r ($ stat_arr );
}
?>
simplexml_load_string parsing XML