最简单的写法:设已调试好的新闻浏览程序为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);
}

解决方案 »

  1.   

    大概是如 xuzuning(唠叨) 这样。先输出。然后再用程序读入。生静态页面
      

  2.   

    xuzuning(唠叨) 的方法是对的,但我想要问的重复利用一个新闻显示模板来生成静态页面,并且是一次性地把已存在于数据库的所有新闻通通生成静态页面
      

  3.   

    我想用以下方法把index.php的内容生成静态页面,却不起作用,也没有语法错误,结果根本没有生成123456.htm
    file_put_contents("123456.htm",file_get_contents("http://localhost/test/index.php"))
      

  4.   

    http://community.csdn.net/Expert/topic/3242/3242866.xml?temp=.1050379看这个帖,里面有利用模版生成静态页,然后你做成函数,套上循环就可以了.
    我也在做这东西呢,不过,手上别的事太多,不然的话,已经做出来了.
      

  5.   

    $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++;
    }
      

  6.   

    确实都比较经典。
    ---------------
    设已调试好的新闻浏览程序为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++;
    }