Copy Code code as follows:
<?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;
}
}
?>
php Template usage:
Copy Code code as follows:
$MDL = new Lightpage_template ();
$Mdl->tpl_header = ' zzz ';
$Mdl->tpl_footer = ';
$Mdl->tpl_parsing = ';
$Mdl->tpl_template = ' list.html ';
echo $Mdl->parse_template ();