最简单的写法:设已调试好的新闻浏览程序为new.php
访问时的URL为http://localhost/new.php?id=xxxx,其中xxxx为新闻的id号
另设存放新闻的表为new
则
//连接数据库,略
$rs = mysql_query("select id from naew");
while(list($id) = mysql_fetch_row($rs)) {
file_put_contents("$id.htm",file_get_contents("http://localhost/new.php?id=$id));
}其中函数
file_get_contents在php4.3.0以后可用,不可用时可自定义:
function file_get_contents($filename) {
return join("",file($filename));
}file_put_contents在php5.0.0以后可用,不可用时可自定义:
function file_put_contents($filename, $string) {
$fp = fopen($filename,"w");
fwrite$fp,$string);
fclose($fp);
}
访问时的URL为http://localhost/new.php?id=xxxx,其中xxxx为新闻的id号
另设存放新闻的表为new
则
//连接数据库,略
$rs = mysql_query("select id from naew");
while(list($id) = mysql_fetch_row($rs)) {
file_put_contents("$id.htm",file_get_contents("http://localhost/new.php?id=$id));
}其中函数
file_get_contents在php4.3.0以后可用,不可用时可自定义:
function file_get_contents($filename) {
return join("",file($filename));
}file_put_contents在php5.0.0以后可用,不可用时可自定义:
function file_put_contents($filename, $string) {
$fp = fopen($filename,"w");
fwrite$fp,$string);
fclose($fp);
}
file_put_contents("123456.htm",file_get_contents("http://localhost/test/index.php"))
我也在做这东西呢,不过,手上别的事太多,不然的话,已经做出来了.
//read data from database
$i = 1; //work var
while($array = mysql_fetch_array($resNews))
{
$tpl->set_file("news","news.htm");//news.htm is the template you want to parse
$tpl->set_var(array("title" => $array['title'],
"content" => $array['content'],
"postTime => $array['postTime'],
"author => $array['author']));
$html = $tpl->parse("out","news");
$fp = fopen("$i.htm","w);
fwrite($fp,$html);
fclose($fp);
$i++;
}
---------------
设已调试好的新闻浏览程序为new.php
访问时的URL为http://localhost/new.php?id=xxxx,其中xxxx为新闻的id号
另设存放新闻的表为new
则
//连接数据库,略
$rs = mysql_query("select id from naew");
while(list($id) = mysql_fetch_row($rs)) {
file_put_contents("$id.htm",file_get_contents("http://localhost/new.php?id=$id));
}其中函数
file_get_contents在php4.3.0以后可用,不可用时可自定义:
function file_get_contents($filename) {
return join("",file($filename));
}file_put_contents在php5.0.0以后可用,不可用时可自定义:
function file_put_contents($filename, $string) {
$fp = fopen($filename,"w");
fwrite$fp,$string);
fclose($fp);
}
$tpl = new template();
//read data from database
$i = 1; //work var
while($array = mysql_fetch_array($resNews))
{
$tpl->set_file("news","news.htm");//news.htm is the template you want to parse
$tpl->set_var(array("title" => $array['title'],
"content" => $array['content'],
"postTime => $array['postTime'],
"author => $array['author']));
$html = $tpl->parse("out","news");
$fp = fopen("$i.htm","w);
fwrite($fp,$html);
fclose($fp);
$i++;
}