Analysis of zuitu group buying template engine

Source: Internet
Author: User

Friends who have been familiar with the most common things should be familiar with the parsing function of the most earthy template, which is mainly completed by the file by replacing the Regular Expression and capturing it, similar to the principle of smarty. The following is an analysis of his regular expression replacement.

InThe template. php file contains this code.

 

  __parse(,       =       (!( = (                 = ( '/^(\xef\xbb\xbf)/', '',  );       = ("/\<\!\-\-\s*\\\$\{(.+?)\}\s*\-\-\>/ies", "__replace('<?php \\1; ?>')",       = ("/\{(\\\$[a-zA-Z0-9_\[\]\\\ \-\'\,\%\*\/\.\(\)\>\'\"\$\x7f-\xff]+)\}/s", "<?php echo \\1; ?>",       = ("/\\\$\{(.+?)\}/ies", "__replace('<?php echo \\1; ?>')",       = ("/\<\!\-\-\s*\{else\s*if\s+(.+?)\}\s*\-\-\>/ies", "__replace('<?php } else if(\\1) { ?>')",       = ("/\<\!\-\-\s*\{elif\s+(.+?)\}\s*\-\-\>/ies", "__replace('<?php } else if(\\1) { ?>')",       = ("/\<\!\-\-\s*\{else\}\s*\-\-\>/is", "<?php } else { ?>",       ( = 0;  < 5; ++          = ("/\<\!\-\-\s*\{loop\s+(\S+)\s+(\S+)\s+(\S+)\s*\}\s*\-\-\>(.+?)\<\!\-\-\s*\{\/loop\}\s*\-\-\>/ies", "__replace('<?php if(is_array(\\1)){foreach(\\1 AS \\2=>\\3) { ?>\\4<?php }}?>')",           = ("/\<\!\-\-\s*\{loop\s+(\S+)\s+(\S+)\s*\}\s*\-\-\>(.+?)\<\!\-\-\s*\{\/loop\}\s*\-\-\>/ies", "__replace('<?php   if(is_array(\\1)){foreach(\\1 AS \\2) { ?>\\3<?php }}?>')",           = ("/\<\!\-\-\s*\{if\s+(.+?)\}\s*\-\-\>(.+?)\<\!\-\-\s*\{\/if\}\s*\-\-\>/ies", "__replace('<?php if(\\1){?>\\2<?php }?>')",                  = ("#<!--\s*{\s*include\s+([^\{\}]+)\s*\}\s*-->#i", '<?php include template("\\1");?>',            (!(,                          __replace(      ('\"', '"',  }

Now we analyze Regular Expression replacement:

8th rows

 = ( '/^(\xef\xbb\xbf)/', '',  ); 

Is to filter out the special characters of the utf8 file in windows »¿

Row 9

 = ("/\<\!\-\-\s*\\\$\{(.+?)\}\s*\-\-\>/ies", "__replace('<?php \\1; ?>')", );

Rule Analysis:

<! -- (0 + blank characters) $ {any character except linefeed} 0 + blank characters

 

Combined Mode correction

 

I

 

E "replaced content ")

 

S

 


  = ("/\{(\\\$[a-zA-Z0-9_\[\]\\\ \-\'\,\%\*\/\.\(\)\>\'\"\$\x7f-\xff]+)\}/s", "<?php echo \\1; ?>", );


 

Used to display content

11th rows

 = ("/\\\$\{(.+?)\}/ies", "__replace('<?php echo \\1; ?>')", );

Eg: $ {$ a} corresponds to <? Php echo $ a;?>

12th rows

  = ("/\<\!\-\-\s*\{else\s*if\s+(.+?)\}\s*\-\-\>/ies", "__replace('<?php } else if(\\1) { ?>')", );

 

 = ("/\<\!\-\-\s*\{elif\s+(.+?)\}\s*\-\-\>/ies", "__replace('<?php } else if(\\1) { ?>')", );

 

 

 = ("/\<\!\-\-\s*\{else\}\s*\-\-\>/is", "<?php } else { ?>", );

 

Template <! -- {Else} --> convert to <? Php} else {?>

17th rows

  = ("/\<\!\-\-\s*\{loop\s+(\S+)\s+(\S+)\s+(\S+)\s*\}\s*\-\-\>(.+?)\<\!\-\-\s*\{\/loop\}\s*\-\-\>/ies", "__replace('<?php if(is_array(\\1)){foreach(\\1 AS \\2=>\\3) { ?>\\4<?php }}?>')", );

>

 

18th rows and 17th rows are almost the same. $ k is missing. Others are exactly the same.

 

 

 

19th rows

 = ("/\<\!\-\-\s*\{if\s+(.+?)\}\s*\-\-\>(.+?)\<\!\-\-\s*\{\/if\}\s*\-\-\>/ies", "__replace('<?php if(\\1){?>\\2<?php }?>')", );

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.