$title = 123; function page_template($name, $template) { global $title; $page = file_get_contents('system/pages/'.$name); $template_file = 'system/pages/templates/'.$template; $template_open = fopen($template_file, 'r'); $template_gets = fgets($template_open, filesize($template_file)); $template_explode = explode('|', $template_gets); $template_array_chunk = array_chunk($template_explode, 2); for($i = 0; $i <= count($template_array_chunk); $i++) { $patterns_page = '/'.$template_array_chunk[$i][0].'/i'; $patterns_replace_page = $template_array_chunk[$i][1]; eval("\$patterns_replace_page = \"$patterns_replace_page\";"); $page_result = preg_replace($patterns_page, $patterns_replace_page, $page); } return $page_result; } echo page_template('main.php', 'main.dat');
Why does not a replacement occur? However, if return $ page_result; put in the loop itself, it will be incorrect to replace and output the same thing several times. How to solve a problem?
The main.dat file contains the following:
\ $ USERNAME \ $ | $ title |