无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了PHP创建XML的方法。分享给大家供大家参考,具体如下:
使用DOMDocument类创建xml
config.php
<"mysql"); $host = $doc->createElement("host"); $username = $doc->createElement("username"); $password = $doc->createElement("password"); $database = $doc->createElement("database"); //创建标签内容 $hostval = $doc->createTextNode("127.0.0.1"); $usernameval = $doc->createTextNode("root"); $passwordval = $doc->createTextNode("1234"); $databaseval = $doc->createTextNode("test"); //绑定标签和内容 $host->appendChild($hostval); $username->appendChild($usernameval); $password->appendChild($passwordval); $database->appendChild($databaseval); //关联标签之间的关系 $doc->appendChild($mysql); $mysql->appendChild($host); $mysql->appendChild($username); $mysql->appendChild($password); $mysql->appendChild($database); $doc->save("config.xml");
config.xml
<"1.0" encoding="utf-8""font-size: medium">使用simplexml方法创建xmlconfig.php
<"1.0" encoding="utf-8""host","127.0.0.1"); $host->addAttribute("note","localhost"); $mysql->addchild("username","root"); $mysql->addchild("password","1234"); $mysql->addchild("database","test"); header("Content-type:text/xml;charset=utf-8"); echo $mysql->asXml(); $mysql->asXml("config.xml");config.xml
<mysql> <host note="localhost">127.0.0.1</host> <username>root</username> <password>1234</password> <database>test</database> </mysql>PS:这里再为大家提供几款关于xml操作的在线工具供大家参考使用:
在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson在线格式化XML/在线压缩XML:
http://tools.jb51.net/code/xmlformatXML在线压缩/格式化工具:
http://tools.jb51.net/code/xml_format_compressXML代码在线格式化美化工具:
http://tools.jb51.net/code/xmlcodeformat更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP针对XML文件操作技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 范文芳.1996-FNNTASY【HYPE】【WAV+CUE】
- 纯音入心系列纯音乐《韵味古筝曲》1CD[MP3][146.2MB]
- 纯音入心系列纯音乐《古筝系列-传统乐曲》1CD[MP3][974.7MB]
- 纯音入心系列纯音乐《古筝系列-弦凝指咽声停处》1CD[MP3][656.5MB]
- 群星.1994-大烂片2辑【派森】【WAV+CUE】
- 吴倩莲.1997-望爱【EMI百代】【WAV+CUE】
- 杨千嬅.2002-万紫千红演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郭采洁.2015-Begin.Again爱造飞鸡【华纳】【FLAC分轨】
- 许志安.2011-ON.AND.ON【东亚】【WAV+CUE】
- 潘秀琼.1994-木兰从军【名将】【WAV+CUE】
- 纯音入心系列纯音乐《古筝系列-当流行乐遇到古筝》1CD[MP3][1.9GB]
- 纯音入心系列纯音乐《精选古筝名曲100首》1CD[MP3][388.7MB]
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]