Simplexml_load_string Parse XML

Source: Internet
Author: User

// 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.