这篇文章主要介绍了关于php简单实现解析xml为数组的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
本文实例讲述了PHP简单实现解析xml为数组的方法。分享给大家供大家参考,具体如下:
最近想要做一个插件机制,需要用到xml,在解析xml时候需要转换为数组,特意记录一个此种解析方式
xmlDemo.xml文件:
<?xml version="1.0" encoding="UTF-8"?> <main xmlns="http://www.xiaoetongo.cn" versionCode="1.0"> <controller co="Aritles"> <meth title="测试插件" do="aritle"/> </controller> <controller co="Ari"> <meth title="测试插件" do="ar"/> <meth title="测试插件" do="a"/> </controller> <install><![CDATA[]]></install> <upgrade><![CDATA[]]></upgrade> </main>
php代码:
立即学习“PHP免费学习笔记(深入)”;
海洋影视管理系统(seacms,海洋cms)是一套专为不同需求的站长而设计的视频点播系统,灵活,方便,人性化设计简单易用是最大的特色,是快速架设视频网站首选,只需5分钟即可建立一个海量的视频讯息的行业网站。 海洋cms采用PHP+MYSQL架构,原生PHP代码带来卓越的访问速度和负载能力免去您的后顾之优。海洋cms支持一键转换原max的模板和数据,实现网站无缝迁移到新平台。众多人性化功能设计,超
116
<?php
$xmls=file_get_contents("xmlDemo.xml");
$xml =simplexml_load_string($xmls);
$xmljson= json_encode($xml);
$xml=json_decode($xmljson,true);
var_dump($xml);运行结果:
array(4) {
["@attributes"]=>
array(1) {
["versionCode"]=>
string(3) "1.0"
}
["controller"]=>
array(2) {
[0]=>
array(2) {
["@attributes"]=>
array(1) {
["co"]=>
string(7) "Aritles"
}
["meth"]=>
array(1) {
["@attributes"]=>
array(2) {
["title"]=>
string(12) "测试插件"
["do"]=>
string(6) "aritle"
}
}
}
[1]=>
array(2) {
["@attributes"]=>
array(1) {
["co"]=>
string(3) "Ari"
}
["meth"]=>
array(2) {
[0]=>
array(1) {
["@attributes"]=>
array(2) {
["title"]=>
string(12) "测试插件"
["do"]=>
string(2) "ar"
}
}
[1]=>
array(1) {
["@attributes"]=>
array(2) {
["title"]=>
string(12) "测试插件"
["do"]=>
string(1) "a"
}
}
}
}
}
["install"]=>
array(0) {
}
["upgrade"]=>
array(0) {
}
}相关推荐:
以上就是PHP简单实现解析xml为数组的方法的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号