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

}
?>

simplexml_load_string 解析xml的更多相关文章

  1. 关于php用simplexml_load_string解析xml出现乱码的小结

    最近在做项目时需要通过xml接口读取合作伙伴数据到数据库,在xml解析环节出现有些特殊中文字符乱码的现象.后采取下面的办法终于解决. 1.curl 抓取过来的字符是unicode编码,需要先转换为ut ...

  2. PHP将解析xml变为数组方法

    最近想要做一个插件机制,需要用到xml,在解析xml时候需要转换为数组,特意记录一个此种解析方式 xml文件 <?xml version="1.0" encoding=&qu ...

  3. PHP解析xml

    <?xml version="1.0" encoding="UTF-8"?> <ZIP_result> <result name= ...

  4. php 解析xml

    解析xml,返回一个对象. $obj = simplexml_load_string($XML, 'SimpleXMLElement', LIBXML_NOCDATA); 查看结果var_dump($ ...

  5. php解析xml的几种方式

    php提供几种解析xml的类或方法,包括:Xml parser. SimpleXML,.XMLReader,.DOMDocument. XML Expat Parser: XML Parser使用Ex ...

  6. PHP解析xml的方法

    PHP解析xml的方法<pre><?php /** XML 文件分析类 * Date: 2013-02-01 * Author: fdipzone * Ver: 1.0 * * fu ...

  7. Android 解析XML文件和生成XML文件

    解析XML文件 public static void initXML(Context context) { //can't create in /data/media/0 because permis ...

  8. Android之解析XML

    1.XML:可扩展标记语言. 可扩展标记语言是一种很像超文本标记语言的标记语言. 它的设计宗旨是传输数据,而不是显示数据. 它的标记没有被预定义.需要自行定义标签. 它被设计为具有自我描述性. 是W3 ...

  9. Android之Pull解析XML

    一.Pull解析方法介绍 除了可以使用SAX和DOM解析XML文件,也可以使用Android内置的Pull解析器解析XML文件.Pull解析器的运行方式与SAX解析器相似.它也是事件触发的.Pull解 ...

随机推荐

  1. 仿微软控件的html元素

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     & ...

  2. 6.openssl rsautl和openssl pkeyutl

    rsautl是rsa的工具,相当于rsa.dgst的部分功能集合.可用于签名.验证.加密和解密文件.非对称密钥的密钥是随机生成的,因此不需要也无法指定salt参与加密. pkeyutl是非对称加密的通 ...

  3. gulp 学习笔记 (初识)

    根据极客学院入门视频整理 一.gulp介绍,主要提到了gulp是基于流式来管理运行的,目前完全搞不懂这一套专业术语. 二.gulp的安装使用. 1.首先需要在全局环境下安装gulp npm insta ...

  4. javascript之Dorm

    一.document.getElementById()    根据Id获取元素节点: <div id="div1"> <p id="p1"&g ...

  5. 在php里写sql查询需要注意的事情

    ---恢复内容开始--- 今天往php里写了一条sql查询, $sql = "select * from videos where vuser=".$u: $ret = mysql ...

  6. Java内部类,枚举

    模式: 模板模式: 简单工厂模式: 适配器模式:  interface ICellPhone  {   void sendMsg();  } class Android implements ICel ...

  7. Native wifi API使用

    写于博客园,自己迁过来: 一.WlanOpenHandle打开一个客户端句柄 DWORD WINAPI WlanOpenHandle( __in DWORD dwClientVersion, __re ...

  8. java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.ProgressBar$SavedState

    java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.Progress ...

  9. 提高你css技能的css开发技巧(转载)

    一.resize实现图片对比 resize的语法如下: resize:none | both | horizontal | vertical 案例效果如下图 (鼠标移到左下角白色区域,往右侧拖动,实现 ...

  10. spring-mybatis jar下载地址

    http://central.maven.org/maven2/org/mybatis/mybatis-spring/1.3.0/