“我想知道代码生成的静态页面是生成完就存在还是关闭此页面就消失了。”
当然还存在啦,不然还能叫“静态”吗?所谓“动态”是指执行程序并向浏览器输出页面数据,你截取这个输出保存到文件就“静态”了。
如原有
http://localhost/test.php
将在浏览器产生某以画面
那么
$txt = file_get_contents("http://localhost/test.php");
$fp = fopen("test.htm","w");
fwrite($fp,$txt);
fclose($fp);
以后
你可用
http://localhost/test.htm
见到同样的画面,这个test.htm就是静态页面
当然还存在啦,不然还能叫“静态”吗?所谓“动态”是指执行程序并向浏览器输出页面数据,你截取这个输出保存到文件就“静态”了。
如原有
http://localhost/test.php
将在浏览器产生某以画面
那么
$txt = file_get_contents("http://localhost/test.php");
$fp = fopen("test.htm","w");
fwrite($fp,$txt);
fclose($fp);
以后
你可用
http://localhost/test.htm
见到同样的画面,这个test.htm就是静态页面
收 smarty html
ob_start();
//这里写生成静态页面的数据
$txt = ob_get_contents();
$fp = fopen("test.htm","w");
fwrite($fp,$txt);
fclose($fp);
ob_end_clean();
2.使用模板 (以phplib为例)
$tpl = new template();
$tpl->set_file("test", "test.htm");
$tpl->set_var("a", $a);
$news = $tpl->parse("out", "test");
$fp = fopen("test.htm","w");
fwrite($fp,$news);
fclose($fp);
3. 使用 xuzuning(唠叨)老大的办法
//这里写生成静态页面的数据
include"test.php";//是这样吗??
$txt = ob_get_contents();
$fp = fopen("test.htm","w");
fwrite($fp,$txt);
fclose($fp);
ob_end_clean();
test1.php:
ob_start();
//这里写生成静态页面的数据
include"test.php";//是这样吗??
$txt = ob_get_contents();
$fp = fopen("test.htm","w");
fwrite($fp,$txt);
fclose($fp);
ob_end_clean();
运行了没有动静有什么问题吗。test.htm要不要事先建立