- 论坛徽章:
- 0
|
谁提供一个生成静态页面(html)的方法呀
我网站用的写index.html 的程序,你想看的话也看看吧,写得比较乱.
<?php
//COPYRIGHT (C) 2004 不会游泳的鱼 All Rights Reserved.
//------------------Version : 1.2 -----------------//
//-----------------Mail:cooldgjk@163.com ----------//
include ("config.php" ;
include "CWriteAds.php";
//每列几个数据
$TdCount=4;
//类WriteAds实例化
$WriteAds=new CWriteAds;
//写广告的函数
function MyADS ($FileSn) {
global $doget_open;
$WriteAds=new CWriteAds;
//写广告1到 $doget_open 文件
$WriteAds->;AdsFileName="ads".$FileSn.".txt";
$WriteAds->;OpenFP=$doget_open;
$WriteAds->;WriteAds();
}
//定义函数写入
function WriteDB($TypeName,$TypeID,$StartID) {
global $doget_open;
global $TdCount;
$query_type_count="select count(id) from photo_show where sort=$TypeID";
$query_type_count_result=mysql_query($query_type_count) or die ("eeroor~~" ;
$query_type_count_row=mysql_fetch_array($query_type_count_result);
$TypeCount=$query_type_count_row[0];
$TypeNameB="<br>;<table width=\"760\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\" bordercolor=\"#848200\" bgcolor=\"#A5CBF7\">;<tr>;<td align=center>;<a name=".$TypeID.">;<b>;<color=\"#FFFFFF\">;★★★".$TypeName."★★★</color>;</b>;</a>;</td>;</tr>;</table>;";
fwrite($doget_open,$TypeNameB);
$TableStart="<table width=\"760\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\" bordercolor=\"#848200\">;";
fwrite($doget_open,$TableStart);
$TrCount=(int)($TypeCount/$TdCount);
$TrCount++;
// $StartID=1;
for ($i=1;$i<=$TrCount;$i++) {
$StartTr="<tr>;";
fwrite($doget_open,$StartTr);
$EndID=$i*$TdCount;
$QueryCmd="select * from photo_show where sort=$TypeID order by id desc limit $StartID,$TdCount";
$Result=mysql_query($QueryCmd) or die ("数据库查询error~" ;
while ($Row=mysql_fetch_array($Result)) {
$FileID=$Row['id'];
$FileTitle=$Row['title'];
$TdString="<td width=25%>;<a href=star/".$FileID.".html target=_blank>;".$FileTitle."</a>;</td>;";
fwrite($doget_open,$TdString);
}
$StartID=$i*$TdCount+1;
$EndTr="</tr>;";
fwrite($doget_open,$EndTr);
}
$TableEnd="</table>;";
fwrite($doget_open,$TableEnd);
}
//定义函数把分类写到索引页
function WriteSort() {
global $doget_open;
$TableStart="<table border=0 width=760 align=center>;<tr align=\"center\">;<td>;";
fwrite($doget_open,$TableStart);
$QueryCmd="select * from photo_show_sort";
$Result=mysql_query($QueryCmd);
while ($Row=mysql_fetch_array($Result)) {
$SortString="<a href=#".$Row['id'].">;★".$Row['sort']."★</a>; ";
fwrite($doget_open,$SortString);
}
$TableEnd="</td>;</tr>;</table>;";
fwrite($doget_open,$TableEnd);
}
//连接到数据库
mysql_connect($dbhost,$dbuser,$dbpassword) or die ("cann't connect db server~" ;
mysql_select_db($dbname) or die ("error select db~" ;
//数据库连接完成
//打开index.html索引文件
$filename="$HtmlDir\\index.html";
$doget_open=fopen($filename,"w+" ;
//读取header.html头文件
$doopen_header=fopen("header.html","r" or die ("读取header.html 失败" ;
$html_header_string=fread($doopen_header,filesize("header.html" );
//写header.html文件内容到index.html索引文件
fwrite($doget_open,$html_header_string);
/*
//写广告1到 $doget_open 文件
$WriteAds->;AdsFileName="ads1.txt";
$WriteAds->;OpenFP=$doget_open;
$WriteAds->;WriteAds();
//写广告3到 $doget_open 文件
$WriteAds->;AdsFileName="ads3.txt";
$WriteAds->;OpenFP=$doget_open;
$WriteAds->;WriteAds();
*/
//调用函数写分类到索引页
WriteSort();
//写站点信息到索引页
$SiteMessageNew="<div align=center>;<font color=red>;".$SiteMessage."</font>;</div>;";
fwrite($doget_open,$SiteMessageNew);
$QuerySortCount="select * from photo_show_sort";
$Result=mysql_query($QuerySortCount) or die ("error ~" ;
$StartID=0;
while ($Row=mysql_fetch_array($Result)) {
WriteDB($Row['sort'],$Row['id'],$StartID);
MyADS($Row['id']);
}
//以只读方式打开link.html文档
$doopen_foot=fopen("link.html","r") or die ("读取link.html失败");
$html_foot_string=fread($doopen_foot,filesize("link.html"));
fwrite($doget_open,$html_foot_string);
//link.html文件写入完成
/*
//写广告2
$WriteAds->;AdsFileName="ads2.txt";
$WriteAds->;OpenFP=$doget_open;
$WriteAds->;WriteAds();
//写广告4到 $doget_open 文件
$WriteAds->;AdsFileName="ads4.txt";
$WriteAds->;OpenFP=$doget_open;
$WriteAds->;WriteAds();
//写广告5到 $doget_open 文件
$WriteAds->;AdsFileName="ads5.txt";
$WriteAds->;OpenFP=$doget_open;
$WriteAds->;WriteAds();
*/
//以只读方式打开foot.html文档
$doopen_foot=fopen("foot.html","r") or die ("读取foot.html失败");
$html_foot_string=fread($doopen_foot,filesize("foot.html"));
fwrite($doget_open,$html_foot_string);
//foot.html文件写入完成
//关闭文件
fclose($doget_open);
//输出完成信息
echo "任务完成~";
?>; |
|