时时商务社区

标题: php生成静态页面的简单示例 [打印本页]

作者: qz234    时间: 2018-2-14 05:59

            发布新闻,实现新闻页面静态化,真静态
add.php
[U]复制代码[/U] 代码如下:
添加新闻

   
     新闻标题:
     新闻内容:
     
   

config.php
[U]复制代码[/U] 代码如下:
DB_class.php
[U]复制代码[/U] 代码如下:
host = $host;
   $this->uname = $uname;
   $this->port = $port;
   $this->pwd = $pwd;
   $this->db = $db;
   mysql_connect($host,$uname,$pwd);
   mysql_select_db($this->db);
  }
  public static function Instance()
  {
   if(Db:instance==null){
    include 'config.php';
    return Db:instance = new DB(HOST, USER, PWD, PORT, DB);
   }
   else
    return Db:instance;
  }
  public function query($sql)
  {
   mysql_query("SET NAMES UTF8");
   $query = mysql_query($sql) or die($sql." error");
   if(!$query) return false;
   else   return $query;
  }
  
  public function getAll($sql)
  {
   $query = $this->query($sql);
   if($query)
   {
    while($ret = mysql_fetch_assoc($query))
    {
     $result[] = $ret;
    }
   }   
   return $result;
  }
  
}
?>
doadd.php
[U]复制代码[/U] 代码如下:
$title=$_POST["title"];
$content=$_POST["content"];
$num = uniqid();
$houzui=".html";
$filename=date('Ymd').'/'.$num.$houzui;
$sql="insert into news(title,content,path) values ('{$title}' , '{$content}' , '{$filename}')";
$query = $db->query($sql);
$fp=fopen("model.htm","r");
$str=fread($fp,filesize("model.htm"));
$str=str_replace("{title}",$title,$str);
$str=str_replace("{content}",$content,$str);
fclose($fp);
$dir = dirname($filename);
if(!is_dir($dir)){
mkdir($dir);
}
$handle=fopen($filename,"w");
fwrite($handle,$str);
fclose($handle);

echo "[url=]查看刚才添加的新闻[/url]";
echo "添加新闻";
?>
model.htm
[U]复制代码[/U] 代码如下:





{title}
  
   
      
        {title}
        {content}
      
   
  

            
            
您可能感兴趣的文章:
  • PHP生成静态页面详解
  • 生成静态页面的PHP类
  • 方便实用的PHP生成静态页面类(非smarty)
  • 谈PHP生成静态页面分析 模板+缓存+写文件
  • php 生成静态页面的办法与实现代码详细版
  • 用php的ob_start来生成静态页面的方法分析
  • 比较详细PHP生成静态页面教程
  • php使用标签替换的方式生成静态页面
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2