Template processing new method, using EVAL ()

xiaoxiao2021-03-05  55

Source: http://club.phpe.net/index.php? ACT = ST & F = 2 & t = 9782

1 Tags: (1), variables: {$ key} can be a general variable, array and a member of the class, but the character cannot be used, can only be single quotes' example: {$ value}, {$ a [0]} {$ this-> a ['color']} This is wrong {$ this -> ["color"]} (2), loop: {loop: loop statement} other code {/ loop} support for While Cycle Example: {loop: for ($ I = 10; $ I <= 20; $ I )} Test {$ I} {/ loop} Output (TEST) 20 ~ 30 {LOOP: While ($ I < 10)} Test {$ A [$ 1] {/ loop} Output (TEST) 20 ~ 30 array (3), logic: {logi: conditional statement} other code {/ logi} supports IF, Elseif, Else example : {Logi: IF ($ I == 1)} Test {LOGI: Elseif ($ I == 2)} Test {$ A [$ I]} {/ logi} {LOGI: Else} test {$ a [$ i]} {/ logi} (4), program: {exec: statement} block, can be a function, pay attention to characters can only be used with ', not "example: {EXEC: $ A = 'Hello'. $ i} correct {EXEC: $ a = "Hello $ I"} {EXEC: Echo $ A} {EXEC: Echo Time ()} {EXEC: $ this-> Outpage (1, 2, 'Index.php')} (5), {* Template Note *}: {* Here you will not output *} 2, template output: only output: evAl (CQLCTPL) example: Eval (CQLCTPL "1.tml")) Set of templates: {EXEC: EVAL (CQLCTPL))}: {EXEC: EVAL (CQLCTPL ($ TemplateFile)} {* Here is the other template file in the template *} 3, function original code: Function CQLCTPL ($ file) {$ fp = fopen ($ file, "r"); $ msg = "echo" ". Str_replace (" "", "" ", fread ($ fp, filesis ($ file))). ""; "; fclose ($ fp); $ lystr = array (0 =>" / {loop: ([^}] )} (. ) {/ loop} / si " , 1 => "/ {logi: ([^}] )} (. ) {/ Logi} / si", 2 => "/ {EXEC: ([^}] )} / si", 3 => "/ ({* [^ *] *}) / Si"); $ newstr = array (0 => " "; 1 {echo" 2 ";} echo" ", 1 =>" "; 1 {echo" 2 ";} echo" ", 2 =>" ", echo", 3 => "") RETURN PREG_REPLACE ($ OLDSTR, $ NEWSTR, $ MSG);} 4, Template Example: Template File: 1.Tml Original code

{$ Title} (1.tml) {* this is a Title *} {loop: for ($ I = 0; $ i <10; $ i

} {* loop start *}

{$ body} IS {$ array [$ i]} {* out the msg *} {logi: IF ($ I> 5)}

{$ I} IS Biger Than 5 {* logic start *} {/ logi} {* login end *} {/ loop} {* loop end *} {EXEC: $ TIME = Time ()} {* exec start and end *} {EXEC START And end *} { : echo '

time is'. $ time} {* exec start and end *} {exec: evAl (CQLCTPL ('2.tml'))} {* this is include Other TML *} Template file: 2. The original code

this is other tml (2.tml) {exec: test ()} TML.PHP: "/ {loop: ([^}] )} (. ) {/ loop} / si", 1 => "/ {logi: ([^}] ) } (. ) {/ logi} / Si ", 2 =>" / {EXEC: ([^}] )} / Si ", 3 =>" / ({* [^ *] *}) / Si "); $ newstr = array (0 =>" "; 1 {echo" 2 ";} echo", 1 => "; 1 {echo" 2 ";} echo", 2 => "" 1. Echo "", 3 => "" "RETURN PREG_REPLACE ($ Oldstr, $ NEWSTR, $ MSG);} Function Test () {echo"

This is the second template file, welcome you Test ";} / * Define a function * / $ title =" This is the first template file "; $ body =" Here you have started output "; for ($ i = 0; $ i <10; $ i ) $ Array [$ I] = "Hello World $ I"; EVAL (CQLCTPL ("1.tml")); 5, template output,

转载请注明原文地址:https://www.9cbs.com/read-31914.html

New Post(0)