User Original PHP template class

Source: Internet
Author: User
Tags php source code php template

User Original PHP template class

the following is the PHP source code:
<?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;
}

}
?>

Usage:


$MDL = new Lightpage_template ();
$Mdl->tpl_header = ' zzz ';
$Mdl->tpl_footer = ';
$Mdl->tpl_parsing = ';
$Mdl->tpl_template = ' list.html ';
echo $Mdl->parse_template ();



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.