php文章內(nèi)容分頁(yè)并生成相應(yīng)的htm靜態(tài)頁(yè)面代碼
<?php
$url='test.php?1=1';
$contents="fjka;fjsa;#page#批量生成分成文件并且加上分頁(yè)代碼";
$ptext ='#page#';
ContentsPages($url,$contents,$ptext)
/**
* 函數(shù)名:ContentsPages
* 功能:文章內(nèi)容分頁(yè)
* 參數(shù):$url文章內(nèi)容頁(yè)URL 類型string,$contents文章內(nèi)容頁(yè)內(nèi)容 類型string,$ptext分頁(yè)標(biāo)識(shí) 類型string
* 作者:七夜
* QQ:64438136 linus.php@gmail.com MSN:zhijian@live.com
*/
//文章數(shù)組
$arr = explode($ptext,$contents);
//數(shù)組長(zhǎng)度&總頁(yè)數(shù)
$total = count($arr);
//當(dāng)前頁(yè)
$nowpage = $_GET['pages']?$_GET['pages']:1;
//上頁(yè)
$prepage = $nowpage==1?1:$nowpage-1;
//下頁(yè)
$nextpage = $nowpage>$total-1?$total:$nowpage+1;
//最后一頁(yè)
$lastpage = $total;
$pdiv = '<br /><div style=\"height:30px;width:500px;border:1px; blackground-color:#ff0000;\">';
$pdiv .= "第{$nowpage}頁(yè) / 總{$total}頁(yè) ";
//首頁(yè)鏈接
$pdiv .= "<li style=\"display:inline;\"><a href=\"{$url}&pages=1\" style=\"text-decoration:none;\">首頁(yè)</a></li>";
//上頁(yè)鏈接
$pdiv .= "<li style=\"display:inline;\"><a href=\"{$url}&pages={$prepage}\" style=\"text-decoration:none;\"> 上一頁(yè) </a></li>";
//顯示分頁(yè)列表
$color = '';
for($i = 1; $i<=$total; $i++)
{
if($i == $nowpage)
{
$color= "color:#ff0000;";
}
else
{
$color = '';
}
$pdiv .= " <li style=\"display:inline;\"><a href=\"{$url}&pages={$i}\" style=\"text-decoration:none;\"><span style=\"{$color}\">{$i}</span></a></li>";
}
//下頁(yè)鏈接
$pdiv .= " <li style=\"display:inline;\"><a href=\"{$url}&pages={$nextpage}\" style=\"text-decoration:none;\"> 下一頁(yè)</a></li>";
//末頁(yè)鏈接
$pdiv .= "<li style=\"display:inline;\"><a href=\"{$url}&pages={$lastpage}\" style=\"text-decoration:none;\"> 末頁(yè) </a></li>";
$pdiv .= '</div>';
//輸出內(nèi)容
echo $arr[$nowpage-1];
//不分頁(yè)則不顯示分頁(yè)列表
if( $total <=1) $pdiv = '';
//輸出分頁(yè)列表
echo $pdiv;
?>
下面是相關(guān)靜態(tài)生成頁(yè)面,雖然代碼不正確但思路是沒(méi)問(wèn)題的。
<?
$tmpBody = "fjka;fjsa;{page}批量生成分成文件并且加上分頁(yè)代碼";
$tmpUrl = 'www.dbjr.com.cn';
$tmpUrlarray = explode('.',$tmpUrl);
$tmpArray = explode('{page}',$tmpBody);
$total = count($tmpArray);
$id="2";
if( $total >1 )
{
$tmpStr = '';
for( $i=0;$i<$total;$i++ ) //遍歷所有分頁(yè)
{
if( $i==0 )
{
$str .='<a href='.$id.'.htm class=bodypage target=_self>'.($i+1).'</a> ';
}
else
{
$str .='<a href='.$id.'_'.$i.'.htm class=bodypage target=_self>'.($i+1).'</a> ';
}
}
//批量生成分成文件并且加上分頁(yè)代碼
$str = '<div class=mupage>'.$str.'</div>';
for( $j=0;$j<$total;$j++ )
{
if( $j==0 )
{
$fname =$id.'.htm';
}
else
{
$fname =$id.'_'.$j.'.htm';
}
$tempMu = str_replace('{htmlContent}',$tmpArray[$j].$str,$tempLate);
makeHtml($tempMu,$filePath,$fname); //這個(gè)函數(shù)就不說(shuō)明了,一個(gè)創(chuàng)建文件的代碼
}
$mupage =1;
}
$tempLate = str_replace('{htmlContent}',$tmpBody,$tempLate); //普通文章 以{page}分頁(yè)取出保存到一個(gè)數(shù)組再生成分頁(yè)地址,然后再由根據(jù)explode分的數(shù)組的內(nèi)容生成htm 頁(yè)面
$total=0;
$str='';
$i=0;
$j=0;
/*
本段代碼生成的原理是id_分頁(yè)號(hào)如100_1.htm,100_2.htm這樣的形式,先是把
*/
function makeHtml($tempMu,$filePath,$fname){
$fp = fopen($filePath.$filename, "w");
fwrite($fp, $tempMu);
fclose($fp);
}
?>
- PHP生成HTML靜態(tài)頁(yè)面實(shí)例代碼
- 使用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è)面分析 模板+緩存+寫(xiě)文件
- 用php的ob_start來(lái)生成靜態(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使用get_class_methods()函數(shù)獲取分類的方法
這篇文章主要介紹了php使用get_class_methods()函數(shù)獲取分類的方法,結(jié)合實(shí)例形式分析了get_class_methods()函數(shù)獲取類中成員方法的使用技巧,需要的朋友可以參考下2016-07-07采集郵箱的php代碼(抓取網(wǎng)頁(yè)中的郵箱地址)
由于搞了個(gè)群發(fā)郵件的程序,當(dāng)然沒(méi)郵箱不行,所以寫(xiě)了個(gè)采集郵箱程序2012-07-07PHP錯(cuò)誤抑制符(@)導(dǎo)致引用傳參失敗Bug的分析
今天cici網(wǎng)友發(fā)來(lái)一個(gè)問(wèn)題, 說(shuō)是在函數(shù)調(diào)用參數(shù)前面使用錯(cuò)誤抑制符號(hào)(@)的時(shí)候, 貌似引用傳參就失效了. 他想讓我?guī)退獯馂槭裁?2011-05-05PHP錯(cuò)誤Parse error: syntax error, unexpected end of file in te
這篇文章主要介紹了PHP錯(cuò)誤Parse error: syntax error, unexpected end of file in test.php on line 12解決方法,需要的朋友可以參考下2014-06-06解決微信授權(quán)回調(diào)頁(yè)面域名只能設(shè)置一個(gè)的問(wèn)題
在做項(xiàng)目集成微信登錄以及微信支付的時(shí)候,都需要進(jìn)行用戶授權(quán)。本文主要介紹了關(guān)于網(wǎng)頁(yè)授權(quán)回調(diào)域名的說(shuō)明以及解決微信授權(quán)回調(diào)頁(yè)面域名只能設(shè)置一個(gè)問(wèn)題的方案。需要的朋友可以參考借鑒2016-12-12php 根據(jù)url自動(dòng)生成縮略圖并處理高并發(fā)問(wèn)題
服務(wù)器生成縮略圖的時(shí)機(jī)一般分為兩種:上傳文件時(shí)生成、訪問(wèn)時(shí)生成,下面為大家介紹下php根據(jù)url自動(dòng)生成縮略圖并處理高并發(fā)問(wèn)題2014-01-01PHP擴(kuò)展編寫(xiě)點(diǎn)滴 技巧收集
PHP擴(kuò)展好的資源不多,轉(zhuǎn)的這個(gè)朋友應(yīng)該是個(gè)高手。他在實(shí)踐中摸索出來(lái)的這些經(jīng)驗(yàn)和大家分享。2010-03-03簡(jiǎn)單的pgsql pdo php操作類實(shí)現(xiàn)代碼
這篇文章主要介紹了簡(jiǎn)單的pgsql pdo php操作類,需要的朋友可以參考下2016-08-08