array 转xml 文件 ( )
来源:互联网 发布:爱上理财网络贷款 编辑:程序博客网 时间:2024/06/12 00:28
Array( [groupsarr] => Array ( [re] => Array ( [team_id] => 5069 [team_name] => re [team_des] => re [parent] => 0 [children_count] => 2 [contacts] => Array ( [0] => Array ( [contacts_id] => 5086 [contacts_name] => fasd [contacts_des] => asd [contacts_company] => [contacts_address] => [contacts_profession] => 国家医药管理局 [contacts_offphone] => 323 [contacts_mobile] => 31 [contacts_homephone] => 12 [contacts_email] => 12@3.co [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5069 [contacts_innerphone] => 0 ) ) [groupsarr] => Array ( [33333] => Array ( [team_id] => 5107 [team_name] => 33333 [team_des] => 33333 [parent] => 5069 [children_count] => 3 [groupsarr] => Array ( [555] => Array ( [team_id] => 5108 [team_name] => 555 [team_des] => 555 [parent] => 5107 [children_count] => 1 [contacts] => Array ( [0] => Array ( [contacts_id] => 5110 [contacts_name] => 555555 [contacts_des] => 55555555 [contacts_company] => [contacts_address] => [contacts_profession] => 33333333 [contacts_offphone] => 555555 [contacts_mobile] => 5555 [contacts_homephone] => 555555 [contacts_email] => 55555@192.com [contacts_sex] => [contacts_fax] => 33333 [contacts_group] => 5108 [contacts_innerphone] => 2030 ) ) ) ) ) ) ) [新的部门] => Array ( [team_id] => 5070 [team_name] => 新的部门 [team_des] => 新建的一个部门还没有名字的 [parent] => 0 [children_count] => 10 [contacts] => Array ( [0] => Array ( [contacts_id] => 5085 [contacts_name] => 天涯 [contacts_des] => [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 12 [contacts_mobile] => 12 [contacts_homephone] => 0 [contacts_email] => s@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5070 [contacts_innerphone] => 0 ) [1] => Array ( [contacts_id] => 5092 [contacts_name] => 人之初 [contacts_des] => 22 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 22 [contacts_mobile] => 22 [contacts_homephone] => 22 [contacts_email] => 22@19.cd [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5070 [contacts_innerphone] => 0 ) [2] => Array ( [contacts_id] => 5099 [contacts_name] => 11 [contacts_des] => 111 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 11 [contacts_mobile] => 11 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5070 [contacts_innerphone] => 0 ) ) [groupodd] => Array ( [第三分部] => Array ( [team_id] => 5071 [team_name] => 第三分部 [team_des] => C [parent] => 5070 [children_count] => 0 ) [呜呜] => Array ( [team_id] => 5111 [team_name] => 呜呜 [team_des] => 通天塔 [parent] => 5070 [children_count] => 0 ) ) [groupsarr] => Array ( [第二分部] => Array ( [team_id] => 5072 [team_name] => 第二分部 [team_des] => B [parent] => 5070 [children_count] => 6 [contacts] => Array ( [0] => Array ( [contacts_id] => 5087 [contacts_name] => b [contacts_des] => 1 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 1 [contacts_mobile] => 1 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5072 [contacts_innerphone] => 0 ) [1] => Array ( [contacts_id] => 5089 [contacts_name] => q [contacts_des] => [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 2147483647 [contacts_mobile] => 321123 [contacts_homephone] => 0 [contacts_email] => 0@0.com [contacts_sex] => [contacts_fax] => 1 [contacts_group] => 5072 [contacts_innerphone] => 1001 ) [2] => Array ( [contacts_id] => 5093 [contacts_name] => 22 [contacts_des] => 22 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 22 [contacts_mobile] => 22 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5072 [contacts_innerphone] => 0 ) [3] => Array ( [contacts_id] => 5094 [contacts_name] => 22 [contacts_des] => 222 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 22 [contacts_mobile] => 22 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5072 [contacts_innerphone] => 0 ) [4] => Array ( [contacts_id] => 5095 [contacts_name] => 11 [contacts_des] => 11 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 11 [contacts_mobile] => 11 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5072 [contacts_innerphone] => 0 ) ) [groupodd] => Array ( [特殊一部] => Array ( [team_id] => 5078 [team_name] => 特殊一部 [team_des] => [parent] => 5072 [children_count] => 0 ) ) ) [第一分部] => Array ( [team_id] => 5073 [team_name] => 第一分部 [team_des] => 1 [parent] => 5070 [children_count] => 3 [contacts] => Array ( [0] => Array ( [contacts_id] => 5096 [contacts_name] => 22 [contacts_des] => 22 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 22 [contacts_mobile] => 22 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5073 [contacts_innerphone] => 0 ) [1] => Array ( [contacts_id] => 5097 [contacts_name] => 22 [contacts_des] => 22 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 22 [contacts_mobile] => 22 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5073 [contacts_innerphone] => 0 ) [2] => Array ( [contacts_id] => 5098 [contacts_name] => 123 [contacts_des] => 22 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 22 [contacts_mobile] => 22 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5073 [contacts_innerphone] => 0 ) ) ) [guest] => Array ( [team_id] => 5075 [team_name] => guest [team_des] => [parent] => 5070 [children_count] => 2 [contacts] => Array ( [0] => Array ( [contacts_id] => 5088 [contacts_name] => 22 [contacts_des] => [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 22 [contacts_mobile] => 22 [contacts_homephone] => 22 [contacts_email] => 22@22.cn [contacts_sex] => [contacts_fax] => 22 [contacts_group] => 5075 [contacts_innerphone] => 0 ) [1] => Array ( [contacts_id] => 5091 [contacts_name] => 33 [contacts_des] => 33 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 33 [contacts_mobile] => 33 [contacts_homephone] => 22 [contacts_email] => 22@22.cn [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5075 [contacts_innerphone] => 2024 ) ) ) [poi] => Array ( [team_id] => 5076 [team_name] => poi [team_des] => [parent] => 5070 [children_count] => 2 [contacts] => Array ( [0] => Array ( [contacts_id] => 5090 [contacts_name] => 22 [contacts_des] => 22 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 22 [contacts_mobile] => 22 [contacts_homephone] => 22 [contacts_email] => 22@22.cn [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5076 [contacts_innerphone] => 0 ) [1] => Array ( [contacts_id] => 5106 [contacts_name] => 张三 [contacts_des] => [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 2147483647 [contacts_mobile] => 213123 [contacts_homephone] => 22 [contacts_email] => 22@22.cn [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5076 [contacts_innerphone] => 0 ) ) ) [最大分部] => Array ( [team_id] => 5077 [team_name] => 最大分部 [team_des] => [parent] => 5070 [children_count] => 6 [contacts] => Array ( [0] => Array ( [contacts_id] => 5100 [contacts_name] => q [contacts_des] => q [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 1 [contacts_mobile] => 1 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5077 [contacts_innerphone] => 0 ) [1] => Array ( [contacts_id] => 5101 [contacts_name] => 2 [contacts_des] => 2 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 2 [contacts_mobile] => 2 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5077 [contacts_innerphone] => 0 ) [2] => Array ( [contacts_id] => 5102 [contacts_name] => 3 [contacts_des] => 3 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 3 [contacts_mobile] => 3 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5077 [contacts_innerphone] => 0 ) [3] => Array ( [contacts_id] => 5103 [contacts_name] => 5 [contacts_des] => 5 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 5 [contacts_mobile] => 5 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5077 [contacts_innerphone] => 0 ) [4] => Array ( [contacts_id] => 5104 [contacts_name] => 6 [contacts_des] => 6 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 6 [contacts_mobile] => 6 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5077 [contacts_innerphone] => 0 ) [5] => Array ( [contacts_id] => 5105 [contacts_name] => 7 [contacts_des] => 7 [contacts_company] => [contacts_address] => [contacts_profession] => [contacts_offphone] => 7 [contacts_mobile] => 7 [contacts_homephone] => 1 [contacts_email] => 1@1.com [contacts_sex] => [contacts_fax] => 0 [contacts_group] => 5077 [contacts_innerphone] => 0 ) ) ) ) ) ) [groupodd] => Array ( [A] => Array ( [team_id] => 5074 [team_name] => A [team_des] => A [parent] => 0 [children_count] => 0 ) [a] => Array ( [team_id] => 5079 [team_name] => a [team_des] => a [parent] => 0 [children_count] => 0 ) ))
<?xml version="1.0" encoding="UTF-8" ?>
代码如下:
$convertArr 为上面数组
function joinXmlStr($convertArr,$type){
$joinedXmlStr = "<?xml version='1.0' encoding='UTF-8' ?>/n<conf type=".$type." >/n<groups>";
echo "<pre>"; print_r($convertArr["groups"]);echo "</pre>";
$joinedXmlStr .= treeArray2Xml($convertArr["groups"]);
$joinedXmlStr .= "</groups>/n</conf>";
return $joinedXmlStr;
}
/*
* 数组转xml字符串格式
* @aurhor liuniuyyou
* @version 2009-09-09
* @access public
* @param $alyArr 传入的要转化的数组
* @return string
*/
function treeArray2Xml($alyArr) {
static $xmlStr;
foreach ($alyArr as $tag => $tmp) {
if($tag == "groupsarr"){
foreach ($tmp as $key => $attr) { #print_r($attr);
$xmlStr .= "/t<group";
foreach ($attr as $chil_key => $chil_value) {
if(trim($chil_key)=="groupsarr" ){
treeArray2Xml($attr);
}
if(!is_array($chil_value)){
$xmlStr .= " ".$chil_key."='" .$chil_value."' ";
if($chil_key == "children_count")
$xmlStr .= " >/n";
}
}
if((count($attr) == 6 && array_key_exists("contacts",$attr))||(count($attr) == 6 && array_key_exists("groupodd",$attr)) || (count($attr) == 7 && array_key_exists("contacts",$attr) && array_key_exists("groupodd",$attr))) //到了部门的最后一级
treeArray2Xml($attr);
$xmlStr .= " /t</group>/n";
}
}elseif($tag == "contacts"){
foreach ($tmp as $key => $attr) {
$xmlStr .= "/t/t<contact" ;
foreach ($attr as $chil_key => $chil_value) { #print_r($chil_value);
$xmlStr .= " ".$chil_key."='" .$chil_value."' ";
}
$xmlStr .= " />/n";
}
}elseif($tag == "groupodd"){
foreach ($tmp as $key => $attr) {
$xmlStr .= "/t<group";
foreach ($attr as $chil_key => $chil_value) { #print_r($chil_value);
$xmlStr .= " ".$chil_key."='" .$chil_value."' ";
}
$xmlStr .= " ></group>/n";
}
}
}
return $xmlStr;
}
php 中调用
exec("sudo -u root:root chmod -R 777 /var/www/html/modules/phonecontact/data/ ");
exec("sudo -u root:root chown -R root:root /var/www/html/modules/phonecontact/data/");
$xmlStr= joinXmlStr(getTreeData($pDB),'es610');
$kl = file_put_contents("/var/www/html/modules/phonecontact/data/Phonebook.xml",$xmlStr);
- array 转xml 文件 ( )
- XML转array
- array转xml 互换
- Android xml文件里读取string array
- 【xml array】通过xml资源文件定义数组
- 基于xml文件生成array文件(使用与seo)
- php xml转array的方法
- Android xml文件里定义并获取string array,integer array,尺寸和颜色
- xml to array 方法
- simplexml to array and array to xml
- excle转xml文件
- properties文件转xml
- datagrid 的dataProvider (array、XML)
- Android xml array数组使用
- php返回xml,json,array
- 在xml中添加array
- php将xml变成array
- array与xml转换实现
- URL中文传值乱码
- 存储过程从入门到熟练(多个存储过程完整实例及调用方法)
- 轉DataGridView的绑定
- http://nptclick.nptcn.net.cn:9000/10/191480
- 使用WINDOWS的GDI开发游戏(6)完结篇
- array 转xml 文件 ( )
- Hadoop分布式文件系统:架构和设计
- gridview获取当前行索引的方法
- 操作组合表头(js)
- 【转】在JSP/Servlet 中编码格式的设置问题
- alter后redirect,提醒窗口不能弹出来
- 嵌入式Linux学前建议(初学者必读)
- The Road to RAD (B) note
- Index was outside the bounds of the array.错误解决