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

php文章内容分页并生成相应的htm静态页面代码_php技巧

php 搞代码 4年前 (2022-01-26) 25次浏览 已收录 0个评论
 <BR><?php <BR>$url='test.php?1=1'; <BR>$contents="fjka;fjsa;#page#批量生成分成文件并且加上分页代码"; <BR>$ptext ='#page#'; <BR>ContentsPages($url,$contents,$ptext) <BR>/** <BR>* 函数名:ContentsPages <BR>* 功能:文章内容分页 <BR>* 参数:$url文章内容页URL 类型string,$contents文章内容页内容 类型string,$ptext分页标识 类型string <BR>* 作者:七夜 <BR>* QQ:64438136 [email protected] MSN:[email protected] <BR>*/ <BR>//文章数组 <BR>$arr = explode($ptext,$contents); <BR>//数组长度&总页数 <BR>$total = count($arr); <BR>//当前页 <BR>$nowpage = $_GET['pages']?$_GET['pages']:1; <BR>//上页 <BR>$prepage = $nowpage==1?1:$nowpage-1; <BR>//下页 <BR>$nextpage = $nowpage>$total-1?$total:$nowpage+1; <BR>//最后一页 <BR>$lastpage = $total; <BR>$pdiv = '<br /><div style="height:30px;width:500px;border:1px">'; <BR>$pdiv .= "第{$nowpage}页 / 总{$total}页  "; <BR>//首页链接 <BR>$pdiv .= "<li>首页</li>"; <BR>//上页链接 <BR>$pdiv .= "<li>  上一页  </li>"; <BR>//显示分页列表 <BR>$color = ''; <BR>for($i = 1; $i<=$total; $i++) <BR><a style="color:transparent">、本文来源gao($daima.com搞@代@#码$网</a><big>搞gaodaima代码</big>{ <BR>if($i == $nowpage) <BR>{ <BR>$color= "color:#ff0000;"; <BR>} <BR>else <BR>{ <BR>$color = ''; <BR>} <BR>$pdiv .= "  <li><span>{$i}</span></li>"; <BR>} <BR>//下页链接 <BR>$pdiv .= "  <li>  下一页</li>"; <BR>//末页链接 <BR>$pdiv .= "<li>  末页  </li>"; <BR>$pdiv .= '

‘;
//输出内容
echo $arr[$nowpage-1];
//不分页则不显示分页列表
if( $total <=1) $pdiv = '';
//输出分页列表
echo $pdiv;
?>


下面是相关静态生成页面,虽然代码不正确但思路是没问题的。

<? <BR>$tmpBody = "fjka;fjsa;{page}批量生成分成文件并且加上分页代码"; <BR>$tmpUrl = 'www.gaodaima.com'; <BR>$tmpUrlarray = explode('.',$tmpUrl); <BR>$tmpArray = explode('{page}',$tmpBody); <BR>$total = count($tmpArray); <BR>$id="2"; <BR>if( $total >1 ) <BR>{ <BR>$tmpStr = ''; <BR>for( $i=0;$i<$total;$i++ ) //遍历所有分页 <BR>{ <BR>if( $i==0 ) <BR>{ <BR>$str .=''.($i+1).' '; <BR>} <BR>else <BR>{ <BR>$str .=''.($i+1).' '; <BR>} <BR>} <BR>//批量生成分成文件并且加上分页代码 <BR>$str = '<div class="mupage">'.$str.'

‘;
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); //这个函数就不说明了,一个创建文件的代码
}
$mupage =1;
}
$tempLate = str_replace(‘{htmlContent}’,$tmpBody,$tempLate); //普通文章 以{page}分页取出保存到一个数组再生成分页地址,然后再由根据explode分的数组的内容生成htm 页面
$total=0;
$str=”;
$i=0;
$j=0;
/*
本段代码生成的原理是id_分页号如100_1.htm,100_2.htm这样的形式,先是把
*/
function makeHtml($tempMu,$filePath,$fname){
$fp = fopen($filePath.$filename, “w”);
fwrite($fp, $tempMu);
fclose($fp);
}
?>


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

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

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

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