The processing of the template engine's logical statement processing for a single layer for loop

Source: Internet
Author: User
Tags html comment preg

First on the code

Private Function Moldforext () {//Template single-layer for loop processing $sql= $this->sql_obj; $URL = $this->url_obj;require ($this datafile); $con = $this->moldfilecontent; $con =str_replace ("\ n", "< #tmoldbr #>", $con); $preg _for_str= "/<! \-\-\s*for\[([a-za-z_\-0-9]+):([a-za-z_\-0-9]+] \]\s*\-\-> ([^!] *) <!\-\-\s*endfor\s*\-\->/";p Reg_match_all ($preg _for_str, $con, $preg _for_match); $preg _for_num=count ($preg _for_match[0]); for ($for _tem_i=0; $for _tem_i< $preg _for_num; $for _tem_i++) {$tem _for_st= $preg _for_match[1][$for _ Tem_i]; $tem _for_ed= $preg _for_match[2][$for _tem_i];if (isset ($ $tem _for_st) &&isset ($ $tem _for_ed)) {$for _ tem_start=$ $tem _for_st, $for _tem_end=$ $tem _for_ed; $for _tem_con= ""; for ($for _tem_j= $for _tem_start; $for _tem_j<$ For_tem_end, $for _tem_j++) {$tttem _for_com= $preg _for_match[3][$for _tem_i]; $tttem _for_com=str_replace ("{". $tem _ For_st. "})", $for _tem_j, $tttem _for_com); $for _tem_con.= $tttem _for_com;} $con =str_replace ($preg _for_match[0][$for _tem_i], $for _tem_con, $con);}} $this->moldfilecontent=str_repLace ("< #tmoldbr #>", "\ n", $con);} 

Actually, it's still based on regular expressions.

The For loop style written in the template is as follows

<!--For[strat:end]--> HTML code ...<!--endfor-

It is written as an HTML comment in order to prevent typographical errors when browsing only the template file.

The start of the For loop identifies the existence of the $start in the template data file, where variable variables are used inside PHP, and the value of a variable is used as a variable name.

The processing of the template engine's logical statement processing for a single layer for loop

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.