echo "生成文件".$indexpath."失败!"; //修改为echo
}
fclose ($handle); //关闭指针
}
fclose ($fp);
die ("生成分页文件完成,如生成不完全,请检查文件权限系统后重新生成!");
?>
third:smarty模版生成静态页面
smarty自己有一个fetch函数,其功用有点类似于fread()可以用来生成静态的页面.
这个例子大家想必看起来眼熟,对,smarty手册中关于fetch函数的例子,比竟官方的例子总是很经典的嘛!
PHP代码
<?php
include("Smarty.class.php");
$smarty = new Smarty;
$smarty->caching = true;
// only do db calls if cache doesn't exist
if(!$smarty->is_cached("index.tpl"))
{// dummy up some data
$address = "245 N 50th";
$db_data = array("City" => "Lincoln", "State" => "Nebraska", "Zip" => "68502");
$smarty->assign("Name","Fred");
$smarty->assign("Address",$address);
$smarty->assign($db_data);
}// capture the output
$output = $smarty->fetch("index.tpl");
//这个地方算是关键// do something with $output here
echo $output; //hoho 看到output的结果了吧 然后呢?fwrite一下,我们就得到我们所要的结果了。
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
?>
PHP代码
<?php
ob_start();
echo "Hello World!";
$content = ob_get_contents();//取得php页面输出的全部内容
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
?>







