<?
#----------新闻页面显示程序-------------------
#              总模板
#          Written by: 21bird
#           date:2002.7.6
#---------------------------------------------
         ob_start();
?>
<html>
<head>
<title>新闻页</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
....
...
..
</body>
</html>
<?
  $aFile = $newspath . $idd . ".php";
  $aFile = fopen($aFile, "w");
  fwrite($aFile, ob_get_contents());
  fclose($aFile);
  ob_end_clean();
  displayInfo("成功生成新闻页面!");
?>

解决方案 »

  1.   

    $idd 是我动态生成的唯一标示,
    $newspath是新闻存放目录,
    生成文件名的扩展名为.php是因为我生成的是php脚本文件,
    因为我在
    那些中放了php脚本,来include了另一些php脚本。:)
    怎么样?够乱吧:p
      

  2.   

    数据库实现
    字段  id(key,自动增加)  1 2 …… content1 content2……
          html静态页面的文件名   必要的标记          页面内容
    需要改变的只有content部分         
    浅妄薄见,望与斟酌
      

  3.   

    呵呵,的确够乱了。你的output buffer用得不错,值得学习。
    我的思路不是这样的:专门写一个程序负责把输入的新闻标题 作者 来源 内容 套入模版中就可以了。
      

  4.   

    呵呵,被逼无奈啊,头儿要求还有评论呢,
    评论的输入和显示必须在新闻下面,那地方必须要连数据库的程序,
    可是在新闻没生成之前,哪里知道该怎么连那?
    所以我在中间加的更复杂那:p21bird小声说:其实这是我在学php的时候在书上刚看到的,
    正好项目需要,顺手就用这个了:)
      

  5.   

    给你一个简单的实例:
    新闻模版文件news_tmp.html:
    <html>
    <head>
    <title>{title}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <body>
    <TABLE border=0 width=767 cellspacing="0" cellpadding="5">
      <TR>
    <TD>
          <div align="center">{news_title}</div>
        </TD>
    </TR>
    <TR>
    <TD>
          <div align="center">{news_image}</div>
        </TD>
    </TR>
    <TR>
    <TD>{news_content}</TD>
    </TR>
    </TABLE>
    </body>
    </html>
      

  6.   

    新闻生成文件aaa.php:
    <?
    //假设下面信息都来自表单
    $title="娱乐新闻---郑秀文准备宣布退出娱乐圈";
    $news_title="郑秀文准备宣布退出娱乐圈";
    $image_path=array("image/xxx.jpg","image/xxx2.jpg","image/xxx3.jpg");
    $news_content="事业如日方中的郑秀文(Sammi),除是乐坛天后外,亦以五百五十万片酬登上全港片酬最高女星之位......";
    $fp=@fopen("news_tmp.html","r") or die("没有模版文件或者没有相关权限!");
    $str=fread($fp,filesize("news_tmp.html"));
    fclose($fp);
      

  7.   

    $news_filename=time().".html"; //生成的新闻文件名
    $str=str_replace("{title}",$title,$str);
    $str=str_replace("{news_title}",$news_title,$str);
    $str=str_replace("{news_content}",$news_content,$str);
    if(count($image_path)){
    for($n=0;$n<count($image_path);$n++)
    $news_image.="<img src=".$image_path[$n]."><BR>";
    $str=str_replace("{news_image}",$news_image,$str);
    }else
    $str=str_replace("{news_image}","",$str);
    $fw=fopen($news_filename,"w");
    fwrite($fw,$str);
    ?>