php下将XML转换为数组
时间:2024-05-09 14:48:04
// Xml 转 数组, 包括根键
function xml_to_array( $xml )
{
$reg = "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/";
if(preg_match_all($reg, $xml, $matches))
{
$count = count($matches[0]);
for($i = 0; $i < $count; $i++)
{
$subxml= $matches[2][$i];
$key = $matches[1][$i];
if(preg_match( $reg, $subxml ))
{
$arr[$key] = xml_to_array( $subxml );
}else{
$arr[$key] = $subxml;
}
}
}
return $arr;
}
// Xml 转 数组, 不包括根键
function xmltoarray( $xml )
{
$arr = xml_to_array($xml);
$key = array_keys($arr);
return $arr[$key[0]];
}
标签:php,XML,数组
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
在Pandas中导入CSV数据时去除默认索引的方法汇总
2023-03-16 02:35:53
python控制nao机器人身体动作实例详解
2023-08-26 11:33:17
python unittest单元测试的步骤分析
2022-03-21 05:59:10
Go语言string,int,int64 ,float之间类型转换方法
2023-06-28 15:20:30
Python对多个sheet表进行整合实例讲解
2021-01-15 06:18:24
PHP实现通过正则表达式替换回调的内容标签
2024-05-13 09:25:39
python能做哪些生活有趣的事情
2023-05-07 01:50:43
![](https://img.aspxhome.com/file/2023/2/131452_0s.png)
phpword插件导出word文件时中文乱码问题处理方案
2024-05-13 09:24:03
基于Python实现对比Exce的工具
2022-12-04 17:44:44
![](https://img.aspxhome.com/file/2023/4/70894_0s.png)
Python pandas常用函数详解
2023-06-18 22:49:37
在pycharm中使用matplotlib.pyplot 绘图时报错的解决
2021-05-22 10:37:31
![](https://img.aspxhome.com/file/2023/2/80602_0s.jpg)
对Python中for复合语句的使用示例讲解
2023-07-19 17:50:44
javascript 操作符(~、&、|、^、<<、>>)使用案例
2024-02-25 18:15:41
mysql索引对排序的影响实例分析
2024-01-18 16:52:29
![](https://img.aspxhome.com/file/2023/1/114001_0s.jpg)
Python地图四色原理的遗传算法着色实现
2022-10-07 20:57:45
![](https://img.aspxhome.com/file/2023/5/75955_0s.jpg)
php中$_GET与$_POST过滤sql注入的方法
2023-07-13 14:38:12
python如何正确使用yield
2023-09-29 16:57:05
如何在网页中制作虚线表格
2010-10-20 20:07:00
webstorm添加vue.js支持的方法教程
2024-04-30 10:16:14
![](https://img.aspxhome.com/file/2023/5/130295_0s.png)
thinkPHP中配置的读取与C方法详解
2023-11-14 17:12:35