xml数据转数组
2016-06-18 16:48
337 查看
xml数据转化数组
$xml = file_get_contents("abc.xml");
$ob= simplexml_load_string($xml); //将xml数据转换成对象
$objson = json_encode($ob);
$objson = str_replace('<','<',$objson);
$obarr = json_decode($objson,true);
function d($obarr){
foreach($obarr as $k => $v){
if(is_array($v)){
foreach($v as $key => $val){
if($key=='@attributes'){
unset($obarr[$k]['@attributes']);
}if($key=='item'){
foreach($val as $keyy => $vall){
if($keyy=='@attributes'){
unset($obarr[$k]['item']['@attributes']);
}if($keyy=='item'){
}
}
}
}
}
}
return $obarr;
}
$s = d($obarr['item']);
$s['name'] = "zhangsan's";
$s['sex'] = "man";
echo "<pre>";
print_r($s);
$xml = file_get_contents("abc.xml");
$ob= simplexml_load_string($xml); //将xml数据转换成对象
$objson = json_encode($ob);
$objson = str_replace('<','<',$objson);
$obarr = json_decode($objson,true);
function d($obarr){
foreach($obarr as $k => $v){
if(is_array($v)){
foreach($v as $key => $val){
if($key=='@attributes'){
unset($obarr[$k]['@attributes']);
}if($key=='item'){
foreach($val as $keyy => $vall){
if($keyy=='@attributes'){
unset($obarr[$k]['item']['@attributes']);
}if($keyy=='item'){
}
}
}
}
}
}
return $obarr;
}
$s = d($obarr['item']);
$s['name'] = "zhangsan's";
$s['sex'] = "man";
echo "<pre>";
print_r($s);
相关文章推荐
- Android UiAutomator :关于Object属性clickable为false处理
- Memcache知识点梳理
- 个人附加作业+期末作业附加题
- github Top100
- MySQl中关于Cardinality的理解
- 2016年读书总结(一)
- 计算机视觉-相机参数标定
- java—代理技术的学习与总结
- 通过Toolbox下wct工具来配置IHS Web服务器及其 Plugins插件
- 访问者模式(Visitor)Java
- 树莓派移动网络连接(配置4G网卡)
- Spring Boot集成MyBatis与分页插件
- 用c语言实现求一个字符串长度的函数
- Ubuntu安装MAC界面
- python笔记一_简单的基础
- myBatis set parameters是提示无效列索引
- iOS开发——导航栏的一些小设置
- C++14 make_index_sequence原理
- linux X界面 输入密码正确,但是无法登陆系统,命令行界面可以登陆
- 【机房收费个人重构—思想篇】