Let's share my template engine. You are welcome to make a brick. The Post was last edited by xuzuning from 2012-05-2315: 02: 49. don't talk about it. go directly to the code template. php (3.55 K) & lt ;? Phpclass & nbsp; template & nbsp ;{& nbsp; & nbsp; protected & nbsp; $ data & nbsp; array: click on my template engine.
This post was last edited by xuzuning at 15:02:49
Don't talk about it more. directly add the code
Template. php (3.55 K)
Class template {
Protected $ data = array ();
Protected $ drillmode = 0;
Function _ construct ($ s ){
If (file_exists ($ s) $ s = file_get_contents ($ s );
$ This-> find_var ($ s );
$ This-> data = explode ('<', $ s );
$ This-> data [0] ='
';
$ This-> find_dsn ();
}
// Add the run method,
Function run (){
// Include "data: //,". join ('<', $ this-> data );
Eval ('?> '. Join (' <', $ this-> data ));
}
Function find ($ pattern ){
$ This-> pattern = $ pattern;
Return array_filter ($ this-> data, array ($ this, 'Find _ callback '));
}
Private function find_dsn (){
Foreach ($ this-> find ("# \ bdsn \ B # I") as $ k => $ v ){
$ T = $ this-> find_tag ($ tag = strtok ($ v, ''), $ k );
End ($ t );
$ Dsn [] = array ($ k, key ($ t ));
}
If ($ this-> drillmode ){
Foreach ($ this-> find ("# \ bdrill \ B # I") as $ k => $ t ){
Foreach ($ dsn as $ I =>$ v) if ($ k <$ v [1] & $ k> $ v [0]) $ t = $ I;
$ Drill [] = $ dsn [$ t];
Unset ($ dsn [$ t]);
}
}
Foreach ($ dsn as $ v ){
List ($ start, $ end) = $ v;
Preg_match ('/\ bdsn \ s * = \ s * ([^ \ s>] +)/I', $ this-> data [$ start], $ reg );
$ This-> data [$ start] = str_replace (''. $ reg [0],'', $ this-> data [$ start]);
$ M = explode (',', trim ($ reg [1], '\' "') + array (0, 0 ,'');
$ Code_start = "? Php if (isset (\ $ _ var) \ $ _ st [] =\$ _ var; foreach (isset (\ $ _ var ['$ m [0]'])? \ $ _ Var ['$ m [0]']: \ $ this-> $ m [0] ('$ m [1]', '$ m [2]') as \ $ _ key =>\$ _ var) {?> ";
$ Code_end = "? Php }\$ _ var = array_pop (\$ _ st);?> ";
Switch ($ m [1]) {
Case 0:
$ T = explode ('>', $ this-> data [$ start]);
$ T [1] = "<$ code_start". $ t [1];
$ This-> data [$ start] = join ('>', $ t );
$ This-> data [$ end] = "$ code_end <". $ this-> data [$ end];
Break;
Case 1:
$ This-> data [$ end]. = "<$ code_end ";
$ This-> data [$ start] = "$ code_start <". $ this-> data [$ start];
Break;
Default:
$ N = round (100/$ m [1]);
$ This-> data [$ end]. ="<$ Code_end ";
$ This-> data [$ start] = "$ code_start
<". $ This-> data [$ start];
Break;
}
}
If ($ this-> drillmode) foreach ($ drill as $ v ){
List ($ start, $ end) = $ v;
Preg_match ('/\ bdsn \ s * = \ s * ([^ \ s>] +)/I', $ this-> data [$ start], $ reg );
$ This-> data [$ start] = str_replace (''. $ reg [0],'', $ this-> data [$ start]);
$ M = explode (',', trim ($ reg [1], '\' "') + array (0, 0 ,'');
$ Code = '';
For ($ I = $ start; $ I <= $ end; $ I ++ ){
$ Code. = '<'. $ this-> data [$ I];
If ($ I> $ start) unset ($ this-> data [$ I]);
}
$ Code = addslashes ($ code );