首页 > 语言 > PHP > 正文

PHP简单实现解析xml为数组的方法

2024-05-05 00:03:30
字体:
来源:转载
供稿:网友

本文实例讲述了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 ["@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程序设计有所帮助。


注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选