//单页生成html页
<?php
ob_start();#开启服务器缓存
    include_once '../gsjj.php';
    $ctx=ob_get_contents();#获取缓存
    ob_end_clean();#清空缓存
    $fh=fopen("../gsjj.html","w+"); 
    fwrite($fh,$ctx);#写入html,生成html
    fclose($fh); 
    echo "<script>alert('文件生成成功');location.href='makehtml.php';</script>";
?>
//新闻列表带分页生成html页
<?php
$fp = fopen ("../new.html","r"); //只读方式打开 new.html模板,将文件指针指向文件头
$content = fread ($fp,filesize ("../new.html")); //读取整个文件内容
$list = '';
$num=0;
$sql= "select * from news ";
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result))
{//查询entries表,取出列表项
$num++;
if($row["url"]=="")
{
$list .= "<ul class='news' id='ul'><li><a href='".$row["tid"].".html'>".$row['title']."</a></li></ul>";
}
else
常用的php代码实例{
$list .= "<ul class='news' id='ul'><li><a href='".$row["url"]."' target='_blank'>".$row['title']."</a></li></ul>";
}
}
$content= str_replace ("{articletable}",$list,$content);
//生成列表结束
// echo $content;
$filename = "../news.html";
$filename1 = "../new.html";
$handle = fopen ($filename,"w"); //打开文件指针,创建文件
/*
 检查文件是否被创建且可写
*/
if (!is_writable ($filename)){
die ("文件:".$filename."不可写,请检查其属性后重试!");
}
if (!fwrite ($handle,$content)){ //将信息写入文件
die ("生成文件".$filename."失败!");
}
fclose ($handle); //关闭指针
die ("Create file ".$filename." success !");
?>
模板页:
<div id="mydiv">
{articletable}
</div>
<div id="changpage" ></div>
<script>
var obj,j;
var page=0;
var nowPage=0;//当前页
var listNum=40;//每页显示<ul>数
var PagesLen;//总页数
var PageNum=500;//分页链接接数(5个)
onload=function(){
ElementById("mydiv").getElementsByTagName("ul");
j=obj.length
il(j/listNum);
upPage(0)
}
function upPage(p){
nowPage=p
//内容变换
for (var i=0;i<j;i++){
obj[i].style.display="none"
}
for (var i=p*listNum;i<(p+1)*listNum;i++){
if(obj[i])obj[i].style.display="block"
}
//分页链接变换
strS='<a href="###" onclick="upPage(0)" >首页</a> '
var PageNum_2=PageNum%2==il(PageNum/2)+il(PageNum/2)
var PageNum_3=PageNum%2==il(PageNum/2):il(PageNum/2)+1
var strC="",startPage,endPage;
if (PageNum>=PagesLen) {startPage=0;endPage=PagesLen-1}
else if (nowPage<PageNum_2){startPage=0;endPage=PagesLen-1>PageNum?PageNum:PagesLen-1}//首页
else {startPage=nowPage+PageNum_3>=PagesLen?PagesLen-PageNum-1: nowPage-PageNum_2+1;var t=startPage+PageNum;endPage=t>PagesLen?PagesLen-1:t}
for (var i=startPage;i<=endPage;i++){
if (i==nowPage)strC+='<a href="###" onclick="upPage('+i+')">'+(i+1)+'</a> '
else strC+='<a href="###" onclick="upPage('+i+')">'+(i+1)+'</a> '
}
strE=' <a href="###" onclick="upPage('+(PagesLen-1)+')" >尾页</a> '
strE2=nowPage+1+"/"+PagesLen+"页"+" 共"+j+"条"
ElementById("changpage").innerHTML=strS+strC+strE+strE2
}
</script>
</div>
//文章生成html
<?php
  mt_srand((double)microtime()*1000000);
        $randval = mt_rand(1, 99999);
        $tmp_num = $randval;
        $title=$_POST['title'];
        $gjc=$_POST['gjc'];
        $content=trim($_POST['content']);
        $bz=$_POST['bz'];
        $url=$_POST['url'];
        $shijian=date("Y-m-d");
        $mobanpath=$root."../newxinxi.html";
        $fp=fopen($mobanpath,"rb");
        $news_contents=fread($fp,filesize($mobanpath));
        $news_contents=str_replace("{-news_title-}",$title,$news_contents);
        $news_contents=str_replace("{-news_gjc-}",$gjc,$news_contents);
        $news_contents=trim(str_replace("{-content-}",$content,$news_contents));
        $news_contents=str_replace("{-bz-}",$bz,$news_contents);
        $news_contents=str_replace("{-shijian-}",$shijian,$news_contents);
        $news_contents=str_replace("{-url-}",$url,$news_contents);
        $news_contents=str_replace("{-shijian-}",$shijian,$news_contents);
        $list = '';
        $num=1;
        $sql= "select * from news order by id desc limit 0,1";
        $result=mysql_query($sql);
        while($row=mysql_fetch_assoc($result))
        {//查询entries表,取出列表项
        /*$num=$nmu+1;    */
        $id=$row["id"]+1;   
       
        $filename="".$tmp_num.".html";   
       
            }
            $num++;
        $newspath=$root."../".$filename;       
        $fp1=fopen($newspath,"w");       
        fwrite($fp1,$news_contents,strlen($news_contents));
       
        $sql="insert into news (title,shijian,content,gjc,bz,url,tid) values ('$_POST[title]','$shijian','$_POST[content]','$_POST[gjc]','$_POST[bz]','$_POST[url]','$tmp_num')";
        $result=mysql_query($sql);
        echo "<script>";
        echo "alert('新闻添加成功!');";
        echo "window.location=('news.php');";
        echo "</script>";       

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。