Generate the processing framework of the smarttemplate Template

Source: Internet
Author: User
? Php/*** generate the smarttemplate template processing framework *** the smarttemplate template class has a high efficiency and the code size is very large. /**
* Generate the processing framework of the smarttemplate template.
*
* The smarttemplate template class is highly efficient and has a small code size.
* Its scalable template functions are even more unique.
*
* Although there are only a few methods, it is easy to use.
* However, after the template file is adjusted, it takes some time to map the processing program to the template.

* This program is used to analyze the template file and provide the framework of the template processing program.
**/

Ob_start ();

$ Template_name = "include/main.html ";
$ Str = file_get_contents ($ Template_name );
Preg_match_all ("/ | {\ W. *}/U ", $ str, $ regs );

$ Stack = array ();
$ Vars = array ();
$ Functions = array ();
$ Key = 0; // = chr (ord ("I") + count ($ stack ));
$ LF = "\ r \ n ";
$ Outstr = "";
Foreach ($ regs [0] as $ v ){
If (preg_match_all ("/ /", $ V, $ r )){
Array_push ($ stack, $ r [1] [0]);
$ K = chr (ord ("I") + $ key ++ );
$ Outstr. = str_repeat (chr (9), $ key-1 ). "/* assign a value to the array \ $ {$ r [1] [0]} */$ LF ";
$ Outstr. = str_repeat (chr (9), $ key-1 ). "for (\ $ k = 0; \ $ k <1; \ $ k ++) \ {$ LF ";
} Elseif (preg_match_all ("/ /", $ V, $ r )){
$ V = array_pop ($ stack );
$ Outstr. = str_repeat (chr (9), -- $ key). "} $ LF ";
If ($ key ){
$ K = chr (ord ("I") + $ key-1 );
$ P = $ stack [$ key-1];
$ Outstr. = str_repeat (chr (9), $ key ). "\ $ {$ p} [\ $ k] [$ v] =\$ $ v; $ LF ";
} Else
$ Outstr. = "\ $ data [$ v] =\$ $ v; $ LF ";
} Elseif (preg_match_all ("/{(\ w +)}/", $ v, $ r )){
If (count ($ stack )){
$ V = $ stack [$ key-1];
$ K = chr (ord ("I") + $ key-1 );
$ Outstr. = str_repeat (chr (9), count ($ stack )). "\ $ {$ v} [\ $ k] [{$ r [1] [0]}] = '{$ r [1] [0]} test '; $ LF ";
$ Ch = "\ $ data [". join ("] [] [", $ stack). "] [{$ r [1] [0]}]";
If (! In_array ($ ch, $ vars ))
$ Vars [] = $ ch;
} Else
If (! In_array ("\ $ data [{$ r [1] [0]}]", $ vars )){
$ Vars [] = "\ $ data [{$ r [1] [0]}]";
$ Outstr. = "\ $ data [{$ r [1] [0]}] = '{$ r [1] [0]} test'; $ LF ";
}
} Elseif (preg_match_all ("/{(\ w +) :( [^}] +)/", $ v, $ r )){
$ Ch = $ r [1] [0]. "({$ r [2] [0]})";
$ Define = true;
If (! @ Include ("smarttemplate_extensions/smarttemplate_extension_serverr.php "))
$ Define = false;
$ Functions [] = array (name => $ ch, define => $ define );
Foreach (split (",", $ r [2] [0]) as $ v)
If ($ v [0]! = '"')
If (! In_array ($ v, $ vars )){
$ Vars [] = "\ $ data [$ v]";
$ Outstr. = "\ $ data [$ v] = '$ v test'; $ LF ";
}
} Elseif (preg_match_all ("/

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.