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 }?>')", );