首页 > 开发 > PHP > 正文

网友原创的PHP模板类

2024-05-04 23:05:21
字体:
来源:转载
供稿:网友

网友原创的php模板类

以下是php源代码:
<?php
    class lightpage_template {
    
        var $tpl_header;
        var $tpl_footer;
        var $tpl_parsing;
        var $tpl_template;
        var $tpl_dirname;
        
        var $tpl_parse_string;
        var $tpl_parse_array;
        
        var $tpl_result;
        
        function __construct() {
            $this->tpl_header = null;
            $this->tpl_footer = null;
            $this->tpl_parsing = array();
            $this->tpl_template = ’list.html’;
            $this->tpl_toparse = null;
            
            $this->tpl_parse_string = array();
            $this->tpl_parse_array = array();
            
            $this->tpl_result = null;
            return true;
        }
        
        function parse_template() {
            $this->tpl_parse_string = array();
            $this->tpl_parse_array = array();
            if($this->tpl_header!=null) { array_push($this->tpl_parse_string,$this->tpl_header);array_push($this->tpl_parse_array,’{header}’); }
            if($this->tpl_footer!=null) { array_push($this->tpl_parse_string,$this->tpl_footer);array_push($this->tpl_parse_array,’{footer}’); }
            if(count($this->tpl_parsing)!=1) {
                foreach($this->tpl_parsing as $tpl_key => $tpl_value) {
                    array_push($this->tpl_parse_string,$tpl_value);
                    array_push($this->tpl_parse_array,’{’.$tpl_key.’}’);
                }
            }
            if($this->tpl_template!=null && $this->tpl_toparse==null) {
                $this->tpl_toparse = file_get_contents(root.’./templates/’.$this->tpl_template);
            } 
            $this->tpl_result = str_replace($this->tpl_parse_array,$this->tpl_parse_string,$this->tpl_toparse);
            return $this->tpl_result;
        }
    
    }
?> 

用法:


$mdl = new lightpage_template();
    $mdl->tpl_header = ’zzz’;
    $mdl->tpl_footer = ’’;
    $mdl->tpl_parsing = ’’;
    $mdl->tpl_template = ’list.html’;
    echo $mdl->parse_template(); 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表