CopyCode The Code is 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. '}');
}< BR >}< br> if ($ this-> tpl_template! = NULL & $ this-> tpl_toparse = NULL) {
$ this-> tpl_toparse = file_get_contents (root. '. /templates /'. $ this-> tpl_template);
}< br> $ this-> tpl_result = str_replace ($ this-> tpl_parse_array, $ this-> tpl_parse_string, $ this-> tpl_toparse);
return $ this-> tpl_result;
}
}
?>
PHP template usage: Copy codeThe Code is 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 ();