+ -
当前位置:首页 → 问答吧 → 为什么什么也没有显示?

为什么什么也没有显示?

时间: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>&it;$key&gt;</font><br/>";
  if(is_array($val)){
  $xml.=$this->_array_to_xml($val,$space_num);
  $xml.=$this->print_space($space_num)."<font color=red>&it;/".$key."&gt;</font><br/>";
  }else{
  $xml.=$this->print_space($space_num)."<b>$val</b><br/>";
  $xml.=$this->print_space($space_num)."<font color=red>&it;/".$key."&gt;</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>&it;$key&gt;</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>&it;/".$key."&gt;</font><br/>";
         }else{
         $this->xml.=$this->print_space($space_num)."<b>$val</b><br/>";
         $this->xml.=$this->print_space($space_num)."<font color=red>&it;/".$key."&gt;</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