php生成xml
首页->学习资料->编程语言->php教程->php技巧 关键词: 发布时间:2018-12-19 10:05:34 浏览次数:1191
<?php
$arr=[
    0=>[
        'name'=>'张三',
        'site'=>'http://www.hu-rong.com',
    ],
    1=>[
        'name'=>'李四',
        'site'=>'www.hu-rong.com',
    ],
];
$dom=new DOMDocument('1.0','utf-8');
$list=$dom->createElement('list');
foreach($arr as $k=>$v){
    $item=$dom->createElement('item');
    $index=$dom->createAttribute('index');
    $index->value=$k;
    $item->appendChild($index);
    $name=$dom->createElement('name');
    $name->appendChild($dom->createCDATASection($v['name']));
    $site=$dom->createElement('site',$v['site']);
    $item->appendChild($name);
    $item->appendChild($site);
    $list->appendChild($item);
}
$dom->appendChild($list);
$dom->save('test.xml');



生成效果:


<?xml version="1.0" encoding="utf-8"?>

<list>

    <item index="0">

        <name><![CDATA[张三]]></name>

        <site>http://www.hu-rong.com</site>

    </item>

    <item index="1">

        <name><![CDATA[李四]]></name>

        <site>www.hu-rong.com</site>

    </item>

</list>



赞:(0)
踩:(0)
相关文章
phpexcel设置行高及列宽,背景颜色,
单点登录sso原理及php实现方式及de
在php中用curl请求java接口无法获
免费ip地址查询接口
php,java,android, aes加解密-加密
地图上计算两点间的距离
关于百度地图的一些技巧
php中empty,is_null,isset的区别
windows及linux下composer安装教程
一种精妙的数据查询与存储方式
热门文章
win7中将文件拷贝到虚拟机linux下
phpexcel设置行高及列宽,背景颜色,
rabbitmq无法启动
intellij idea不显示git push按钮
php7中使用mongodb的aggregate进行
centos7.4 64位下swoole安装及配置
laravel页面静态化的方法
navicate连接mycat报1184错误
单点登录sso原理及php实现方式及de
devops-jenkins容器为pending状态
好评文章
phpexcel设置行高及列宽,背景颜色,
php7中使用mongodb的aggregate进行
intellij idea打开文件所在文件夹
windows下使用MongoDB Compass Com
win7中将文件拷贝到虚拟机linux下
laravel 中悲观锁 & 乐观锁的使用
单点登录sso原理及php实现方式及de
navicate连接mycat报1184错误
rabbitmq无法启动
laravel整合dingo/api方法步骤:jwt
标签
rabbitmq mysql备份 elasticsearch golang swoole
我的项目
【github】www.github.com/hurong241
【码云】gitee.com/hu_rong/projects
【docker hub】hub.docker.com/repositories/hurong241
【packagist】packagist.org/users/hurong241/packages
站点信息
建站时间:2011年
文章数:610篇
浏览数:953068
粤ICP备18028092号-1  微信:hurong241