• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-26) 43次浏览 已收录 0个评论

发布新闻,实现新闻页面静态化,真静态


add.php

<BR> 添加新闻<br><br> <body><BR>    <BR>     新闻标题:<br><BR>     新闻内容:<textarea name="content" cols="100" rows="25"></textarea><br><BR>     <BR>   <BR> <BR><BR>

config.php

<?php <BR> define("HOST", "localhost");<BR> define("USER", "justfan");<BR> define("PWD", "justfan");<BR> define("DB", "justfanDB");<BR> define("PORT", "3360");<BR>?><BR>

DB_class.php

<?php<BR> class DB<BR> {<BR>  private $host = '';<BR>  private $uname = '';<BR>  private $pwd = '';<BR>  private $port = '';<BR>  private $db = '';<BR><mark style="color:transparent">本%文来源gaodaimacom搞#^代%!码网@</mark>搞代gaodaima码     public static $instance = null; <br><br>  private function __construct($host , $uname , $pwd , $port , $db)<BR>  {<BR>   $this->host = $host;<BR>   $this->uname = $uname;<BR>   $this->port = $port;<BR>   $this->pwd = $pwd;<BR>   $this->db = $db;<br><br>   mysql_connect($host,$uname,$pwd);<BR>   mysql_select_db($this->db);<BR>  }<br><br>  public static function Instance()<BR>  {<BR>   if(Db::$instance==null){<BR>    include 'config.php';<BR>    return Db::$instance = new DB(HOST, USER, PWD, PORT, DB);<BR>   } <BR>   else <BR>    return Db::$instance;<BR>  }<br><br>  public function query($sql)<BR>  {<BR>   mysql_query("SET NAMES UTF8");<BR>   $query = mysql_query($sql) or die($sql." error");<BR>   if(!$query) return false;<BR>   else   return $query;<BR>  }<br><br>  <BR>  public function getAll($sql)<BR>  {<BR>   $query = $this->query($sql);<BR>   if($query)<BR>   {<BR>    while($ret = mysql_fetch_assoc($query))<BR>    {<BR>     $result[] = $ret;<BR>    }<BR>   }   <BR>   return $result;<BR>  }<br><br>  <BR> }<BR>?><BR>

doadd.php

<?php <BR>include 'DB_class.php';<BR>$db = DB::Instance();</P><P>$title=$_POST["title"];<BR>$content=$_POST["content"]; </P><P>$num = uniqid();<BR>$houzui=".html";<BR>$filename=date('Ymd').'/'.$num.$houzui;</P><P>$sql="insert into news(title,content,path) values ('{$title}' , '{$content}' , '{$filename}')";<BR>$query = $db->query($sql);</P><P>$fp=fopen("model.htm","r");<BR>$str=fread($fp,filesize("model.htm"));<BR>$str=str_replace("{title}",$title,$str);<BR>$str=str_replace("{content}",$content,$str);<BR>fclose($fp);</P><P>$dir = dirname($filename);<BR>if(!is_dir($dir)){<BR> mkdir($dir);<BR>}</P><P>$handle=fopen($filename,"w"); <BR>fwrite($handle,$str); <BR>fclose($handle);</P><P> </P><P>echo "查看刚才添加的新闻";<BR>echo "添加新闻";<BR>?><BR>

model.htm

<BR><BR><BR> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><BR> <script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script><BR> <script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script><BR> <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"><BR> <link rel="stylesheet" href="../bootstrap/css/common.css"><BR> <title>{title}</title><BR><BR>  <body></P><P>    <div class="container"><BR>      <div class="jumbotron"><BR>        <h1>{title}</h1><BR>        <p>{content}</p><BR>      






搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php生成静态页面的简单示例_php实例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址