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);
}
?>
simplexml_load_string 解析xml的更多相关文章
- 关于php用simplexml_load_string解析xml出现乱码的小结
最近在做项目时需要通过xml接口读取合作伙伴数据到数据库,在xml解析环节出现有些特殊中文字符乱码的现象.后采取下面的办法终于解决. 1.curl 抓取过来的字符是unicode编码,需要先转换为ut ...
- PHP将解析xml变为数组方法
最近想要做一个插件机制,需要用到xml,在解析xml时候需要转换为数组,特意记录一个此种解析方式 xml文件 <?xml version="1.0" encoding=&qu ...
- PHP解析xml
<?xml version="1.0" encoding="UTF-8"?> <ZIP_result> <result name= ...
- php 解析xml
解析xml,返回一个对象. $obj = simplexml_load_string($XML, 'SimpleXMLElement', LIBXML_NOCDATA); 查看结果var_dump($ ...
- php解析xml的几种方式
php提供几种解析xml的类或方法,包括:Xml parser. SimpleXML,.XMLReader,.DOMDocument. XML Expat Parser: XML Parser使用Ex ...
- PHP解析xml的方法
PHP解析xml的方法<pre><?php /** XML 文件分析类 * Date: 2013-02-01 * Author: fdipzone * Ver: 1.0 * * fu ...
- Android 解析XML文件和生成XML文件
解析XML文件 public static void initXML(Context context) { //can't create in /data/media/0 because permis ...
- Android之解析XML
1.XML:可扩展标记语言. 可扩展标记语言是一种很像超文本标记语言的标记语言. 它的设计宗旨是传输数据,而不是显示数据. 它的标记没有被预定义.需要自行定义标签. 它被设计为具有自我描述性. 是W3 ...
- Android之Pull解析XML
一.Pull解析方法介绍 除了可以使用SAX和DOM解析XML文件,也可以使用Android内置的Pull解析器解析XML文件.Pull解析器的运行方式与SAX解析器相似.它也是事件触发的.Pull解 ...
随机推荐
- Objective - C - 添加类目 - NSDate
1.类目为系统内部的类或者是没有源代码的类添加方法,不有添加实例变量 2.添加的方法会成为原类的一部分,子类照样可以使用 3.类目的文件名为原类名+文件名 4.既可以添加实例方法,也可以添加类方法 X ...
- WeedFS问题收集
weed fs FAQ Moving files to a different server Q: Hello,is it possible to move manually the .dat and ...
- DNS服务器原理
19.1 什么是DNS 主机名自动解析为 IP 就很重要!那就是 DNS. 19.1.1 用网络主机名取得IP的历史渊源 单一档案处理上网的年代: /etc/hosts 利用某些特定的 ...
- SAMBA 服务器原理
SAMBA服务器 16.1.1 什么是SAMBA 在早期,一般使用FTP来传文件: 不过使用 FTP 传输档案却有个小小的问题, 那就是 你无法直接修改主机上面的档案数据!也就是说,你想要更改 ...
- css小知识之伪元素
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...
- 需要交互的shell编程——EOF(转载)
在shell编程中,”EOF“通常与”<<“结合使用,“<<EOF“表示后续的输入作为子命令或子shell的输入,直到遇到”EOF“, 再次返回到主调shell,可将其理解为分 ...
- apk添加系统签名
上一节,可以通过添加su的方式获取系统权限,但这种存在安全隐患,故不推荐,本文通过获取数字签名方式获取系统权限. 在我们的AndroidManifest.xml中添加 android:share ...
- python实现监控URL的一个值小于规定的值--邮件报警
监控URL的一个值小于规定的值--邮件报警 #!/usr/bin/env python #-*- coding:utf-8 -*- __author__ = 'liudong' import urll ...
- ES 集群
http://www.cnblogs.com/o-andy-o/p/5067184.html
- linux在home目录下使用ls命令卡死
linux在home目录下使用ls命令卡死,原因可能是mount的某个服务器挂掉或出啥问题了,这个时候umount掉就正常了,如果umount提示device is busy,这时可以使用强制卸载 ...