PHP生成HTML靜態(tài)頁(yè)面實(shí)例代碼
更新時(shí)間:2008年08月31日 12:21:38 作者:
本程序作用是從PHP生成HTML靜態(tài)頁(yè)面并存儲(chǔ)到以年份和月份為名稱創(chuàng)建的目錄。讀取全部數(shù)據(jù)批量生成,全部生成后彈出提示??芍付ㄅ紊蓴?shù)量,建議不超過800,否則執(zhí)行速度會(huì)有問題。
為cd2sc.com網(wǎng)站功能而開發(fā),代碼為本人原創(chuàng),生成速度一般。
(出于眾所周知的原因,涉及到數(shù)據(jù)庫(kù)的數(shù)據(jù)字段名稱做了改動(dòng),并且為了代碼明晰去掉了參數(shù)過濾的部分)
說明:原動(dòng)態(tài)地址為 moban.php?id=1 ,生成后地址為 html/200808/sell_1.html 。page.php為分頁(yè)程序,本博客中有發(fā)布。
頁(yè)面使用方式,將本代碼保存為make.php,使用方法為瀏覽器訪問 make.php?t=數(shù)量&pg=頁(yè)面;例如 make.php?t=300&pg=2,即每次生成300條數(shù)據(jù),從數(shù)據(jù)列表第2頁(yè)開始生成,即跳過前面300條。如果不加任何參數(shù),直接訪問make.php,則默認(rèn)每次生成200條,從第一頁(yè)開始生成。
<?php
if($_GET[pg]==''){
$aa=1;
}else{
$aa=$_GET[pg];
}
include("admin/conn.php");
require_once("page.php");
$result=mysql_query("select * from 2carsell ");
$totle=mysql_num_rows($result);
$pagelist = $_GET[t];
if($_GET[t]==''){
$pagelist='200';
}else{
$pagelist=$_GET[t];
}
$pager = new Pager($totle,$pagelist);
$datastat=" 共 <b>".$pager->countall."</b> 條,每次生成 <b>".$pager->countlist."</b> 條,共需生成 <b>".$pager->page."</b> 次";//數(shù)據(jù)統(tǒng)計(jì)
$bb=$pager->page;
$pagenav=$pager->backstr.$pager->thestr.$pager->nextstr;
$limitFrom = $pagelist*($pager->pg-1);
$result=mysql_query("select * from 2carsell ORDER BY id DESC limit $limitFrom,$pagelist");
?>
<center><div style="font-size:14px;"><b>第 <font color=red><?echo $aa?></font > 次頁(yè)面生成中..<? echo $datastat?></b></div><br>
<?
print "<center><textarea name=textarea class=textarea style='width:520px;height:455px'>";
while($datauser=mysql_fetch_array($result)){
$iid=$datauser[id];
$html = file_get_contents("/moban.php?id=".$iid."");
$sql="select * from 2carsell where id=$iid";
$data=mysql_fetch_array(mysql_query($sql));
$path=date("Ym",$data[PutDate]);
$testdir="html/".$path;
if(file_exists ($testdir)):
else:
mkdir ($testdir, 0777);
echo "目錄".$testdir."創(chuàng)建成功!<br>";
endif;
$filename = "html/$path/sell_$iid.html";
// 使用寫入模式打開$filename
if (!$handle = fopen($filename, 'w')) {
print "不能打開文件 $filename";
exit;
}
if (is_writable($filename)) {
// 將$html寫入到我們打開的文件中。
if (!fwrite($handle, $html)) {
print "不能寫入到文件 $filename";
exit;
}
print "文件 $filename 更新成功!\n\r";
fclose($handle);
} else {
print "文件 $filename 不可寫";
}
?>
<? }?>
</textarea>
<br><br>
<div style="font-size=12px"><? echo $datastat." "?></div><br><br>
<?
$aa=$aa+1;
if($aa>$bb){
echo '<font color=blue>恭喜,所有頁(yè)面生成完畢!</font>';
echo "<script>alert('所有文檔生成/更新完畢!')</script>";
}else{
echo "<Script> window.location='make.php?t=$pagelist&pg=$aa'; </script>";
}
?>
(出于眾所周知的原因,涉及到數(shù)據(jù)庫(kù)的數(shù)據(jù)字段名稱做了改動(dòng),并且為了代碼明晰去掉了參數(shù)過濾的部分)
說明:原動(dòng)態(tài)地址為 moban.php?id=1 ,生成后地址為 html/200808/sell_1.html 。page.php為分頁(yè)程序,本博客中有發(fā)布。
頁(yè)面使用方式,將本代碼保存為make.php,使用方法為瀏覽器訪問 make.php?t=數(shù)量&pg=頁(yè)面;例如 make.php?t=300&pg=2,即每次生成300條數(shù)據(jù),從數(shù)據(jù)列表第2頁(yè)開始生成,即跳過前面300條。如果不加任何參數(shù),直接訪問make.php,則默認(rèn)每次生成200條,從第一頁(yè)開始生成。
復(fù)制代碼 代碼如下:
<?php
if($_GET[pg]==''){
$aa=1;
}else{
$aa=$_GET[pg];
}
include("admin/conn.php");
require_once("page.php");
$result=mysql_query("select * from 2carsell ");
$totle=mysql_num_rows($result);
$pagelist = $_GET[t];
if($_GET[t]==''){
$pagelist='200';
}else{
$pagelist=$_GET[t];
}
$pager = new Pager($totle,$pagelist);
$datastat=" 共 <b>".$pager->countall."</b> 條,每次生成 <b>".$pager->countlist."</b> 條,共需生成 <b>".$pager->page."</b> 次";//數(shù)據(jù)統(tǒng)計(jì)
$bb=$pager->page;
$pagenav=$pager->backstr.$pager->thestr.$pager->nextstr;
$limitFrom = $pagelist*($pager->pg-1);
$result=mysql_query("select * from 2carsell ORDER BY id DESC limit $limitFrom,$pagelist");
?>
<center><div style="font-size:14px;"><b>第 <font color=red><?echo $aa?></font > 次頁(yè)面生成中..<? echo $datastat?></b></div><br>
<?
print "<center><textarea name=textarea class=textarea style='width:520px;height:455px'>";
while($datauser=mysql_fetch_array($result)){
$iid=$datauser[id];
$html = file_get_contents("/moban.php?id=".$iid."");
$sql="select * from 2carsell where id=$iid";
$data=mysql_fetch_array(mysql_query($sql));
$path=date("Ym",$data[PutDate]);
$testdir="html/".$path;
if(file_exists ($testdir)):
else:
mkdir ($testdir, 0777);
echo "目錄".$testdir."創(chuàng)建成功!<br>";
endif;
$filename = "html/$path/sell_$iid.html";
// 使用寫入模式打開$filename
if (!$handle = fopen($filename, 'w')) {
print "不能打開文件 $filename";
exit;
}
if (is_writable($filename)) {
// 將$html寫入到我們打開的文件中。
if (!fwrite($handle, $html)) {
print "不能寫入到文件 $filename";
exit;
}
print "文件 $filename 更新成功!\n\r";
fclose($handle);
} else {
print "文件 $filename 不可寫";
}
?>
<? }?>
</textarea>
<br><br>
<div style="font-size=12px"><? echo $datastat." "?></div><br><br>
<?
$aa=$aa+1;
if($aa>$bb){
echo '<font color=blue>恭喜,所有頁(yè)面生成完畢!</font>';
echo "<script>alert('所有文檔生成/更新完畢!')</script>";
}else{
echo "<Script> window.location='make.php?t=$pagelist&pg=$aa'; </script>";
}
?>
您可能感興趣的文章:
- 使用PHP實(shí)現(xiàn)生成HTML靜態(tài)頁(yè)面
- 比較詳細(xì)PHP生成靜態(tài)頁(yè)面教程
- php 生成靜態(tài)頁(yè)面的辦法與實(shí)現(xiàn)代碼詳細(xì)版
- 談PHP生成靜態(tài)頁(yè)面分析 模板+緩存+寫文件
- 用php的ob_start來生成靜態(tài)頁(yè)面的方法分析
- php文章內(nèi)容分頁(yè)并生成相應(yīng)的htm靜態(tài)頁(yè)面代碼
- 方便實(shí)用的PHP生成靜態(tài)頁(yè)面類(非smarty)
- php生成靜態(tài)頁(yè)面的簡(jiǎn)單示例
- PHP生成靜態(tài)頁(yè)面詳解
- php輸出控制函數(shù)和輸出函數(shù)生成靜態(tài)頁(yè)面
相關(guān)文章
PHP + plupload.js實(shí)現(xiàn)多圖上傳并顯示進(jìn)度條加刪除實(shí)例代碼
本篇文章主要介紹了PHP + plupload.js實(shí)現(xiàn)多圖上傳并顯示進(jìn)度條加刪除實(shí)例代碼。具有一定的參考價(jià)值,有興趣的可以了解一下。2017-03-03使用xampp搭建運(yùn)行php虛擬主機(jī)的詳細(xì)步驟
這篇文章主要介紹了通過使用xampp搭建運(yùn)行php虛擬主機(jī)的步驟,介紹很詳細(xì),感興趣的小伙伴們可以參考一下2015-10-10利用PHP腳本在Linux下用md5函數(shù)加密字符串的方法
這篇文章主要介紹了利用PHP腳本在Linux下用md5函數(shù)加密字符串的方法,只需Linux系統(tǒng)中安裝過PHP然后在命令行中操作文中示例即可,需要的朋友可以參考下2015-06-06PHP xpath提取網(wǎng)頁(yè)數(shù)據(jù)內(nèi)容代碼解析
這篇文章主要介紹了PHP xpath提取網(wǎng)頁(yè)數(shù)據(jù)內(nèi)容代碼解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07