Write your own smarty template engine without parsing php (please help) $ realcontent = $ this-> filecontent;
$ Mode = '/\{\$ ([\ w] + )\}/';
If (preg_match ($ mode, $ realcontent )){
Var_dump ($ assign_vars );
$ Realcontent = preg_replace ($ mode ," Assign_vars ['$ 1']?> ", $ Realcontent); // replace it with the variable injected in the index. php file
}
Return $ realcontent;
}
The code after running is
Assign_vars ['content']?>
Author: Assign_vars ['name']?> Assign_vars ['var']?>
Reply to discussion (solution)
{\ $ Title}
Author: {\ $ name}
Country: {\ $ china}
Province: {\ $ provice}
City: {\ $ city}
TEMPLEATE; $ mode = '/\{\$ (\ w +) \}/'; $ assign_arr = array (); function assign ($ name, $ value) {global $ assign_arr; $ assign_arr [$ name] = empty ($ value )? '': $ Value; return $ assign_arr;} function replace_content ($ match) {global $ assign_arr; if (! Empty ($ match) {return array_key_exists ($ match [1], $ assign_arr )? $ Assign_arr [$ match [1]: '';}} assign (" title "," I love you "); assign (" name "," iseagold "); assign ("china", "china"); assign ("provice", "Guangdong province"); assign ("city", "Shenzhen city"); assign ("no ", "The page does not exist. unretrieved variables"); echo preg_replace_callback ($ mode, "replace_content", $ tpl_string ); // ====================================================== simple class version ====================================================== ========================== class Template {public $ assign_items = array (); Public $ content; function _ construct ($ file) {$ this-> content = file_get_contents ($ file);} function assign ($ name, $ value) {$ this-> assign_items [$ name] = empty ($ value )? "": $ Value;} function replace () {$ arr_assign_items = array (); $ content = ''; $ content = $ this-> content; $ arr_assign_items = $ this-> assign_items; $ pattern = '/\{\$ (\ w +) \}/'; $ this-> content = preg_replace_callback ($ pattern, function ($ match) use ($ arr_assign_items) {if (! Empty ($ match) {if (array_key_exists ($ match [1], $ arr_assign_items) {echo $ arr_assign_items [$ match [1]; return $ arr_assign_items [$ match [1] ;}}, $ content) ;}function display () {echo $ this-> content ;}} $ template = new Template ("template_test.html"); $ template-> assign ("title", "I love you"); $ template-> assign ("name ", "iseagold"); $ template-> assign ("china", "china"); $ template-> assign ("provice", "Guangdong province "); $ Template-> assign ("city", "Shenzhen city"); $ template-> assign ("no", "the page does not exist, unretrieved variable "); $ template-> replace (); $ template-> display ();?>
After smarty 3, PHP mixed write is not supported by default. you can replace it with smarty 2.
It's a false positive. it's a write imitation, not a silent write...
It's a false positive. it's a write imitation, not a silent write...
Understand the compilation class, all of which are regular expressions.
You only generated the php code and did not execute it.