PHP之SimpleXML函数
使用php创建XML文件十分简单,使用SimpleXML那就更简便了,同时读取XML文件也十分方便。XML文件是直接在浏览器中打开,以自定义标签的方式直观简洁的方式展示给读者。
1.创建XML文件
header("Content-type: text/html; charset=utf-8");
$xml=new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><returnRequest />');
$item=$xml->addchild("client","DYSON");
$item1=$xml->addchild("distributionCentre","DAMCO");
$item2=$xml->addchild("order");
$item2->addchild("ref",$info_all['id']);
$item2->addchild("id","??");
$item2->addchild("store","CN");
$item3 = $item2->addchild("detail");
$item3->addchild("created",$info_all['crated']);
$item3->addchild("customer");
$item3->addchild("ip");
$item3->addchild("language","cn-GB");
$item3->addchild("vatCountry","CN");
$item3->addchild("origin","DYSON");
$item3->addchild("originDate",$info_all['crated']);
$item3->addchild("customerReference","???");
$item3->addchild("csAgent");
$item4 = $item2->addchild("people");
$item4_1 = $item4->addchild("person");
$item4_1->addchild("ref");
$item4_1->addchild("title");
$item4_1->addchild("firstName",$info_all['receiver_name']);
$item4_1->addchild("lastName");
$item4_1->addchild("phone",$info_all['receiver_mobile']);
$item4_1->addchild("fax");
$item4_1->addchild("mobile");
$item4_1->addchild("email");
$item4_1->addchild("department");
$item4_1->addchild("companyName");
$item4_1->addchild("gender");
$item4_1->addchild("dateofbirth");
$item5 = $item2->addchild("address");
$item5_1 = $item5->addchild("address");
$item5_1->addchild("addresstype","customer");
$item5_1->addchild("addrss1",$info_all['receiver_district']);
$item5_1->addchild("addrss2",$info_all['receiver_address']);
$item5_1->addchild("city",$info_all['receiver_city']);
$item5_1->addchild("state",$info_all['receiver_state']);
$item5_1->addchild("zip",$info_all['receiver_zip']);
$item5_1_1 = $item5_1->addchild("country");
$item5_1_1->addchild("code","CN");
$item5_1_1->addchild("name","CHINA");
header("Content-type: text/xml");
// echo $xml->asXml();exit;
$xml->asXml("test.xml");
使用addchild方法可以无限创建XML标签,同时也可以无限层级,类似多维数组形式。文件打开显示为
2.解析XML文件
$xml = simplexml_load_file("test.xml");
$data['client'] = $xml->client;
$data['language'] = $xml->order->detail->language;
echo $data['language'];
使用 simplexml_load_file 函数可以解析XML文件 可以获取指定标签中的数据 (->标签)箭头指向哪个标签便获取所在标签中的数据。
PHP之SimpleXML函数的更多相关文章
- PHP 5 SimpleXML 函数
PHP SimpleXML 简介 SimpleXML 扩展提供了一种获取 XML 元素的名称和文本的简单方式,只要您知道 XML 文档的布局. SimpleXML 转换 XML 文档到 SimpleX ...
- PHP SimpleXMLElement::__toString SimpleXML 函数
定义和用法 SimpleXMLElement::__toString - 返回字符串内容 版本支持 PHP4 PHP5 PHP7 不支持 支持 支持 语法 SimpleXMLElement::__to ...
- PHP中遍历XML之SimpleXML
简单来讲述一些XML吧,XML是可扩展标记语言,是一种用于标记电子文件使其具有结构性的标记语言.XML是当今用于传输数据的两大工具之一,另外一个是json. 我们在PHP中使用XML也是用来传输数据, ...
- HP SimpleXML
PHP SimpleXML PHP SimpleXML 处理最普通的 XML 任务,其余的任务则交由其它扩展处理. 什么是 PHP SimpleXML? SimpleXML 是 PHP 5 中的新特性 ...
- PHP SimpleXML
安装 SimpleXML 扩展需要 PHP 5 支持. 自 PHP 5 起,SimpleXML 函数是 PHP 核心的组成部分.无需安装即可使用这些函数. PHP 5 SimpleXML 函数 函数 ...
- Php函数完整参考手册
序号 分类 描述 1 Array 函数 2 Calendar 函数 日历扩展包含了简化不同日历格式间的转换的函数. 3 Date/Time 函数 Date/Time 函数用于从 PHP 脚本运行的服务 ...
- PHP XML SimpleXML
PHP 可以基于 SimpleXML 生成和解析 xml 的方法,通过本节的实例,你将了解 PHP 是如何使用 SimpleXML 生成及解析 xml 格式数据的. PHP SimpleXML 处理最 ...
- 什么是 PHP SimpleXML?
PHP SimpleXML PHP SimpleXML 处理最普通的 XML 任务,其余的任务则交由其它扩展处理. 什么是 PHP SimpleXML? SimpleXML 是 PHP 5 中的新特性 ...
- PHP 语言特性
一.PHP 超级全局变量 PHP 超级全局变量列表: $GLOBALS $_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION ...
随机推荐
- 【3】JMicro微服务-服务超时,重试,重试间隔
如非授权,禁止用于商业用途,转载请注明出处作者:mynewworldyyl 接下来的内容都基于[2]JMicro微服务-Hello World做Demo 微服务中,超时和重试是一个最基本问题下面Dem ...
- docker版redmine安装部署
数据库准备 docker run -d --name some-postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=redmine postgr ...
- Web安全篇之SQL注入攻击
在网上找了一篇关于sql注入的解释文章,还有很多技术,走马观花吧 文章来源:http://www.2cto.com/article/201310/250877.html ps:直接copy,格式有点问 ...
- SpringMVC之RequestMappingHandlerMapping
<mvc:annotation-driven content-negotiation-manager="" enable-matrix-variables="tru ...
- Mac 10.12安装VirtualBox
说明:用VirtualBox主要是能开无缝模式. 下载: (链接: https://pan.baidu.com/s/1i5y78Ct 密码: e3bq)
- Visual Studio 跨平台開發實戰(1) - Hello Xamarin! (转帖)
前言 應用程式發展的腳步, 從來沒有停過. 從早期的Windows 應用程式, 到網路時代的web 應用程式, 再到近幾年相當盛行的行動裝置應用程式(Mobile Application), 身為C# ...
- (转)错误"因为数据库正在使用,所以无法获得对数据库的独占访问权"的解决方案
引发原因:是因为我在还原数据库的时候,还有其他的用户正在使用数据库,所以就会出现以上提示. 解决方法:1,设置数据库在单用户模式下工作.设置方法:在需要还原的数据库上右击,在右键菜单命令上选择&quo ...
- maven的安装配置超详细教程【含nexus】
1 下载 下载地址:http://maven.apache.org/download.cgi 界面效果如下: 点击之后进入的apache 软件基金的发布目录,在这里你可以下载apache的所有项目. ...
- C 标准库 - string.h之memcpy使用
memcpy Copy block of memory Copies the values of num bytes from the location pointed to by source di ...
- 安卓加固之so文件加固
一.前言 最近在学习安卓加固方面的知识,看到了jiangwei212的博客,其中有对so文件加固的两篇文章通过节加密函数和通过hash段找到函数地址直接加密函数,感觉写的特别好,然后自己动手实践探索s ...