渲染模板 function render_template($template_file, $variables) { extract($variables, EXTR_SKIP); // Extract the variables to a local namespace ob_start(); // Start output buffering include "./$template_file"; // Include the template file $c
function render_template($template_file, $variables) {
extract($variables, EXTR_SKIP); // Extract the variables to a local namespace
ob_start(); // Start output buffering
include "./$template_file"; // Include the template file
$contents = ob_get_contents(); // Get the contents of the buffer
ob_end_clean(); // End buffering and discard
return $contents; // Return the contents
}
$render_message = array(
'token' => $token,
'me' => $user,
'game_key' => $game_key,
'game_link' => $game_link,
'initial_message' => $initial_message,
);
$template_file = 'index.tpl';
$ret = render_template($template_file, $render_message);
echo($ret);
原文地址:PHP简易渲染模板, 感谢原作者分享。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号