「PHP開発」Smartyとob_start()とで静的htmlを生成するコード
方法1–Smarty
<?php
require(“smarty/Smarty.class.php");
$t = new Smarty;
$t->assign(“title","Welcome to Bei Jing!");
$content = $t->fetch(“templates/index.htm");
$fp = fopen(“news/2016/07/20/demo.html", “w");
fwrite($fp, $content);
fclose($fp);
?>
方法2–ob_start()
<?php
ob_start();
echo “this is a demo “;
$content = ob_get_contents();
$fp = fopen(“news/2016/11/12/demo.html", “w");
fwrite($fp, $content);
fclose($fp);
?>