找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 690|回复: 0
打印 上一主题 下一主题

php生成静态页面的简单示例

[复制链接]

2588

主题

2588

帖子

7694

积分

论坛元老

Rank: 8Rank: 8

积分
7694
跳转到指定楼层
楼主
发表于 2018-2-14 05:59:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            发布新闻,实现新闻页面静态化,真静态
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使用标签替换的方式生成静态页面
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端