function CreatHtml($sorce_name,$target_name)
{
$s_fname = $sorce_name;
$o_fname = $target_name;
ob_end_clean();
ob_start();
include($s_fname);
$length = ob_get_length();
$buffer = ob_get_contents();
$buffer = eregi_replace("  ","",$buffer);
$buffer = eregi_replace("\t","",$buffer);
ob_end_clean();
if ($fp = fopen($target_name,"w+"))
{
if (fwrite($fp,$buffer))
{}
else
{}
fclose($fp);
}
$url = "http://".str_replace("../","",$target_name); echo "<center><p><h3>生成 ".$s_fname." 页成功!!</h3><BR><A HREF=".$url." target=_blank>查看生成效果</A>&nbsp;&nbsp;&nbsp;&nbsp;<A HREF='javascript:history.back()'>返回上一页</A></p></center>";
}使用例子:

解决方案 »

  1.   

    1,你自己要有一个生成规则,尤其是路径和文件名称
    2,可以利用ob函数的取得页面内容再输出静态页面
    3,如果配合服务器的REWRITE功能就更好不过了
      

  2.   

    我这里有个例子,你看看:
    -------------------------------------------------
    <?php
    class CreateHtml
    {
     function mkdir( $prefix= 'article' )
     {
      $y = date('Y');
      $m = date('m');
      $d = date('d');
      $p=DIRECTORY_SEPARATOR;
      $filePath='article'.$p.$y.$p.$m.$p.$d;
      $a=explode($p,$filePath);
      foreach ( $a as $dir)
      {
       $path.=$dir.$p;
       if(!is_dir($path))
       {
        //echo '没有这个目录'.$path;
        mkdir($path,0755);
       }
      }
      return $filePath.$p;  
     }
     function start()
     {
      ob_start();
     }
     function end()
     {
      $info     = ob_get_contents();
      $fileId   = '12345';
      $postfix  = '.html';
      $path     = $this->mkdir($prefix= 'article');
      $fileName = time().'_'.$fileId.$postfix;
      $file=fopen($path.$fileName,'w+');
      fwrite($file,$info);
      fclose($file);
      ob_end_flush();
     }
    }
    ?>
    <?php
    $s=new CreateHtml();
    $s->start();
    ?>
    <html>
    <body>
    HTML页面文字
    </body>
    </html>
    <?php
    $s->end();
    ?>
    -------------------------------------------