Rumah > php教程 > php手册 > PHP简易渲染模板

PHP简易渲染模板

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-06-06 20:12:39
asal
1127 orang telah melayarinya

渲染模板 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
}
Salin selepas log masuk

usage

$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);
Salin selepas log masuk
Label berkaitan:
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan