为什么什么也没有显示?
时间:2011-12-26
来源:互联网
<?php
header("content-type:text/xml");
class array_to_xml{
//属性,生成的xml文档
var $xml;
//方法
//构造函数
function __construct($array,$encoding="gb2312"){
echo "1.<br/>";
$this->xml='';
$this->xml.=$this->_array_to_xml($array,0);
}
//__get()
function __get($property_name){
echo "4.<br/>";
if(isset($this->$property_name)){
return ($this->$property_name);
}
else{
return (NULL);
}
}
//输出一定数量的缩进符号
function print_space($space_num){
$s="";
for($i=0;$i<$space_num;$i++) $s.="——";
return $s;
}
//转换
function _array_to_xml($array,$space_num){
$space_num++;
foreach($array as $key=>$val){
$xml.=$this->print_space($space_num)."<font color=red>⁢$key></font><br/>";
if(is_array($val)){
$xml.=$this->_array_to_xml($val,$space_num);
$xml.=$this->print_space($space_num)."<font color=red>⁢/".$key."></font><br/>";
}else{
$xml.=$this->print_space($space_num)."<b>$val</b><br/>";
$xml.=$this->print_space($space_num)."<font color=red>⁢/".$key."></font><br/>";
}
}
return $xml;
}
}
//定义数组
$arr=array('联系人列表'=>array('联系人'=>array('姓名'=>'张三','编号'=>'001','公司'=>'A公司','电子邮件'=>'[email protected]','电话'=>'12345678','地址'=>array('街道'=>'经十路11#','城市'=>'济南','省份'=>'山东','邮编'=>'250001'))));
//使用
$ax=new array_to_xml($arr);
echo $ax->__get($xml);
?>
输出:
1.
4.
header("content-type:text/xml");
class array_to_xml{
//属性,生成的xml文档
var $xml;
//方法
//构造函数
function __construct($array,$encoding="gb2312"){
echo "1.<br/>";
$this->xml='';
$this->xml.=$this->_array_to_xml($array,0);
}
//__get()
function __get($property_name){
echo "4.<br/>";
if(isset($this->$property_name)){
return ($this->$property_name);
}
else{
return (NULL);
}
}
//输出一定数量的缩进符号
function print_space($space_num){
$s="";
for($i=0;$i<$space_num;$i++) $s.="——";
return $s;
}
//转换
function _array_to_xml($array,$space_num){
$space_num++;
foreach($array as $key=>$val){
$xml.=$this->print_space($space_num)."<font color=red>⁢$key></font><br/>";
if(is_array($val)){
$xml.=$this->_array_to_xml($val,$space_num);
$xml.=$this->print_space($space_num)."<font color=red>⁢/".$key."></font><br/>";
}else{
$xml.=$this->print_space($space_num)."<b>$val</b><br/>";
$xml.=$this->print_space($space_num)."<font color=red>⁢/".$key."></font><br/>";
}
}
return $xml;
}
}
//定义数组
$arr=array('联系人列表'=>array('联系人'=>array('姓名'=>'张三','编号'=>'001','公司'=>'A公司','电子邮件'=>'[email protected]','电话'=>'12345678','地址'=>array('街道'=>'经十路11#','城市'=>'济南','省份'=>'山东','邮编'=>'250001'))));
//使用
$ax=new array_to_xml($arr);
echo $ax->__get($xml);
?>
输出:
1.
4.
作者: f43310 发布时间: 2011-12-26
因为$xml的变量为空,建议不要使用print_space
作者: kkkgho 发布时间: 2011-12-26
PHP code
<?php header("content-type:text/xml"); class array_to_xml{ //属性,生成的xml文档 var $xml; //方法 //构造函数 function __construct($array,$encoding="gb2312"){ echo "1.<br/>"; $this->xml=''; $this->xml.=$this->_array_to_xml($array,0); } //__get() function __get($property_name){ echo "4.<br/>"; if(isset($this->$property_name)){ return ($this->$property_name); } else{ return (NULL); } } //输出一定数量的缩进符号 function print_space($space_num){ $s=""; for($i=0;$i<$space_num;$i++) $s.="——"; return $s; } //转换 function _array_to_xml($array,$space_num){ $space_num++; foreach($array as $key=>$val){ $this->xml.=$this->print_space($space_num)."<font color=red>⁢$key></font><br/>"; if(is_array($val)){ $this->xml.=$this->_array_to_xml($val,$space_num); $this->xml.=$this->print_space($space_num)."<font color=red>⁢/".$key."></font><br/>"; }else{ $this->xml.=$this->print_space($space_num)."<b>$val</b><br/>"; $this->xml.=$this->print_space($space_num)."<font color=red>⁢/".$key."></font><br/>"; } } return $this->xml; } } $arr=array('联系人列表'=>array('联系人'=>array('姓名'=>'张三','编号'=>'001','公司'=>'A公司','电子邮件'=>'[email protected]','电话'=>'12345678','地址'=>array('街道'=>'经十路11#','城市'=>'济南','省份'=>'山东','邮编'=>'250001')))); $ax=new array_to_xml($arr); echo $ax->__get("xml"); ?>
作者: zhiyu27 发布时间: 2011-12-27
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28