PHP生成静态页面简单实例源码

小程序结构很简单,为方便新手PHP程序员研究来用,一看就能懂

<?php
ob_start();
require_once("../inc/conn.php");  //数据库连接文件
$typ=$_POST["typ"];
$title=$_POST["title"];
$content=$_POST["d_content"];
$author=$_POST["author"];
$source=$_POST["source"];
$mobanpath="../moban/moban.html";
if(file_exists($mobanpath))
{
$fp=fopen($mobanpath,"r");
$str=fread($fp,filesize($mobanpath));
$str=str_replace("-title-",$title,$str);
$str=str_replace("-time-",date("Y-m-d H:i:s"),$str);
$str=str_replace("-content-",$content,$str);
$str=str_replace("-author-",$author,$str);
$str=str_replace("-source-",$source,$str);
$foldername=date("Y-m-d");
$folderpath="../newslist/".$foldername;
if(!file_exists($folderpath))
{
mkdir($folderpath);
}
$filename=date("H-i-s").".html";
$filepath="$folderpath/$filename";
if(!file_exists($filepath))
{
$fp=fopen($filepath,"w");
fputs($fp,$str);
fclose($fp);
}
$filepath=$foldername."/".$filename;
$sql="insert into newscontent (newstypeid,newstitle,newspath,newssource,newstime) values ($typ,'$title','$filepath','$source','".date("Y-m-d H:i:s")."')";
mysql_query($sql);
header("location:add.php");
}
?>

张子庭博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论