PHP-Smarty模板引擎应用简教
require "Smarty/libs/Smarty.class.php"; //引入配置文件
$tpl=new Smarty(); //建立对象$tpl
//模板内容替换
$tpl->assign("title","测试用的网页标题");
$tpl->assign("content","测试用的网页内容");
// 上面两行也可以用这行代替
//$tpl->assign(array("title" => "测试用的网页标题", "content" => "测试用的网页内容")); //应用数组替换
$tpl->display('test.html'); //动态显示出替换后的模板内容
/* ==========================
用smarty生成静态页面
//下面这句取得页面中所有内容, 注意最后一个参数为false
$content = $tpl->fetch('test.html',null, null,false);
//下面将内容写入至一个静态文件
$fp = fopen('html/news.html', 'w');
fwrite($fp, $content);
fclose($fp);
============================*/
说明:注意“templates_c”及“templates”路径,默认在网站根目录下
上一篇:PHP计算字符串的长度(包括汉字)
下一篇:PHP中Cookie及其使用
讨论数量:0