zoukankan      html  css  js  c++  java
  • simplexml_load_string 解析xml

    <?php
    //simplexml_load_string 解析两种类型的xml
    $res='<?xml version="1.0" encoding="UTF-8"?>
    <SYNCPacket>
    <mor><cpid>010001000249</cpid><mid>1009011719781282</mid><cpmid>1411957176</cpmid><mobile>13882524228</mobile><port>0096</port><msg>DELIVRD</msg><area>四川</area><city>遂宁</city><type>4</type><channel>1</channel><reserved></reserved></mor>
    <mor><cpid>010001000249</cpid><mid>1009011719781301</mid><cpmid>1411957175</cpmid><mobile>18719295258</mobile><port>0096</port><msg>DELIVRD</msg><area>广东</area><city>阳江</city><type>4</type><channel>1</channel><reserved></reserved></mor>
    </SYNCPacket>';
    $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='<?xml version="1.0" encoding="UTF-8"?>
    <SYNCPacket>
    <count>200</count>
    <result>0</result>
    <report>
    <mor><cpid>010001000249</cpid><mid>1009011719781282</mid><cpmid>1411957176</cpmid><mobile>13882524228</mobile><port>0096</port><msg>DELIVRD</msg><area>四川</area><city>遂宁</city><type>4</type><channel>1</channel><reserved></reserved></mor>
    <mor><cpid>010001000249</cpid><mid>1009011719781301</mid><cpmid>1411957175</cpmid><mobile>18719295258</mobile><port>0096</port><msg>DELIVRD</msg><area>广东</area><city>阳江</city><type>4</type><channel>1</channel><reserved></reserved></mor>
    </report>
    </SYNCPacket>';

    $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);

    }
    ?>

  • 相关阅读:
    基于 HTML5 WebGL 的 3D 仓储管理系统
    基于 HTML5 WebGL 的 3D “弹力”布局
    基于HTML5 Canvas 实现地铁站监控
    基于HTML5的WebGL经典3D虚拟机房漫游动画
    根据矩阵变化实现基于 HTML5 的 WebGL 3D 自动布局
    玩转 HTML5 下 WebGL 的 3D 模型交并补
    基于HTML5 Canvas WebGL制作分离摩托车
    基于HTML5 Canvas的3D动态Chart图表
    基于HTML5 Canvas的工控SCADA模拟飞机飞行
    [iOS]过渡动画之高级模仿 airbnb
  • 原文地址:https://www.cnblogs.com/cwl168/p/4016255.html
Copyright © 2011-2022 走看看