一 : php分页类 只用传入总页数
PHP培训有一段时间了,消失也有一段时间了,特地封装一个分页类上传上来,自己写的,高手指点,新手学习,莫笑话!呵呵
配合CSS样式会好看点.
CODE:
DIV.page {
PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center
}
DIV.page A {
BORDER-RIGHT: #dedfde 1px solid; PADDING-RIGHT: 6px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #dedfde 1px solid; PADDING-LEFT: 6px; PADDING-BOTTOM: 2px; BORDER-LEFT: #dedfde 1px solid; COLOR: #0061de; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #dedfde 1px solid;TEXT-DECORATION: none
}
DIV.page A:hover {
BORDER-RIGHT: #000 1px solid; BORDER-TOP: #000 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #000 1px solid; COLOR: #fff; BORDER-BOTTOM: #000 1px solid; BACKGROUND-COLOR: #0061de;TEXT-DECORATION: none
}
DIV.page A:active {
BORDER-RIGHT: #000 1px solid; BORDER-TOP: #000 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #000 1px solid; COLOR: #fff; BORDER-BOTTOM: #000 1px solid; BACKGROUND-COLOR: #0061de
}
二 : 方便快捷的PHP长文章分页函数
PHP程序员们在编写程序代码的时候,通常都会用到文章的分页等功能的实现。每次编写不同的程序都需要编写一遍文章分页的代码,比较玛法。
- 推荐几种PHP实现页面跳转的方法
- 为你详解PHP页面跳转函数的具体含义
- PHP header函数的详细用法介绍
- 经验分享 总结PHP常用函数
- 一劳永逸 打造简单PHP分页函数
今天我们就为大家写了一段PHP长文章分页函数,方便大家的代码编写:
- <?php
- functionff_page($content,$page)
- {
- global$expert_id;
- $PageLength=2000;//每页字数
- $CLength=strlen($content);
- $PageCount=floor(($CLength
/$PageLength))+1;//计算页数 - $PageArray=array();
- $Seperator=array("\n",
"\r","。","!","?",";
",",","”","’");//分隔符号 - //echo"页数:".$PageCount."<br>";
- //echo"长度:".$CLength."<br><br><br>";
- //strpos()函数返回字符串在
另一个字符串中第一次出现的位置 - if($CLength<$PageLength)
- {
- echo$content;
- }else{
- $PageArray[0]=0;
- $Pos=0;
- $i=0;
- //第一页
- for($j=0;$j<sizeof($Seperator);$j++)
- {
- //echo$Seperator[$j];
- $Pos=strpos($content,
$Seperator[$j],$PageArray[$i]+1900); - while($Pos>0&&$Pos
<($i+1)*$PageLength&&
$Pos>$i*$PageLength) - {
- $PageArray[$i]=$Pos;
- $Pos=strpos($Pos+$PageLength,
$content,$Seperator[$j]); - }
- if($PageArray[$i]>0)
- {
- $j=$j+sizeof($Seperator)+1;
- }
- }
- //---
- for($i=1;$i<$PageCount-1;$i++){
- for($j=0;$j<sizeof($Seperator);$j++)
- {
- //echo$Seperator[$j];
- $Pos=strpos($content,$Seperator
[$j],$PageArray[$i-1]+1900); - while($Pos>0&&$Pos<
($i+1)*$PageLength&&$Pos>
$i*$PageLength) - {
- $PageArray[$i]=$Pos;
- $Pos=strpos($Pos+$PageLength,
$content,$Seperator[$j]); - }
- if($PageArray[$i]>0)
- {
- $j=$j+sizeof($Seperator)+1;
- }
- }
- }
- //--PHP长文章分页函数最后一页
- $PageArray[$PageCount-1]=$CLength;
- //$page=2;
- if($page==1)
- {
- $output=substr($content,0,
$PageArray[$page-1]+2); - }
- if($page>1&&$page<=$PageCount)
- {
- $output=substr($content,$PageArray
[$page-2]+2,$PageArray[$page-1]-$
PageArray[$page-2]); - $output="(上接第".($page-1)."页)\n".$output;
- }
- echostr_replace("\n","<br>
",$output); - //if($page==$PageCount)
- //return$output=substr($content,
$PageArray[$page-2]+2,$PageArray[$page-1]-$PageArray[$page-2]); - if($PageCount>1)
- {
- echo"<br><br><br><center>";
- echo"<fontcolor='ff0000'>".$page."</font>/".$PageCount."页 ";
- if($page>1)
- echo"<ahref=$PHP_SELF?expert_id=$expert_id&page_t=".($page-1).">上一页</a>";
- else
- echo"上一页";
- for($i=1;$i<=$PageCount;$i++)
- {
- echo"<ahref=$PHP_SELF?expert_id=$expert_id&page_t=".$i.">[".$i."]</a>";
- }
- if($page<$PageCount)
- echo"<ahref=$PHP_SELF?expert_id=$expert_id&page_t=".($page+1).">下一页</a>";
- else
- echo"下一页";
- echo"</center>";
- }
- }
- }?>
PHP长文章分页函数的使用
- <?php
- $content1=''测试文字,
尽量长一些,www.corange.cn";- $current=$_REQUEST['page_t'];
- $result=ff_page
($content1,$current);- echo$result;
- ?>
PHP长文章分页函数的使用与实现的代码示例如上所示。
三 : PHP实现对数组分页处理实例详解
本文实例讲述了PHP实现对数组分页处理方法。分享给大家供大家参考,具体如下:
最近用到了用数组数据分页,这里整理了一下,具体代码如下:
<?php class PaginationArray{ public $pageArray=array(); //数组 public $pageSize=10; //每页显示记录数 public $current= 1; //当前页 private $total=0; //总页数 private $prev=0; //上一页 private $next=0; //下一页 public $argumetsOther='';//设置参数 function __construct($array=array(),$pageSize=10,$current=1){ $this->pageArray=$array; $this->pageSize=$pageSize; $this->current=$current; } /*通过数组进行初始化 * * 数组为关联数组,参数索引为pageArray,pageSize,current * */ function setArguments($arr){ if (is_array($arr)){ $this->pageArray=$arr['pageArray']; $this->pageSize=$arr['pageSize']; $this->current=$arr['current']; }else{ return ; } } //返回链接 function page(){ $_return=array(); /*calculator*/ $this->total=ceil(Count($this->pageArray)/$this->pageSize); $this->prev=(($this->current-1)<= 0 ? "1":($this->current-1)); $this->next=(($this->current+1)>=$this->total ? $this->total:$this->current+1); $current=($this->current>($this->total)?($this->total):$this->current); $start=($this->current-1)*$this->pageSize; $arrleng=count($this->pageArray); for($i=$start;$i<($start+$this->pageSize);$i++){ if($i >= $arrleng)break; array_push($_return,$this->pageArray[$i]); } $pagearray["source"]=$_return; $pagearray["links"]=$this->linkStyle(2); return $pagearray; } //链接的样式 private function linkStyle($number=1){ $linkStyle=''; switch ($number){ case 1: $linkStyle="<a href="?page=1">first</a> <a href="?page={$this->prev}">prev</a> <a href="?page={$this->next}">next</a> <a href="?page={$this->total}">end</a>"; break; case 2: $linkStyle="<a href="?page=1&{$this->argumetsOther}">首页</a> <a href="?page={$this->prev}&{$this->argumetsOther}">上一页</a> <a href="?page={$this->next}&{$this->argumetsOther}">下一页</a> <a href="?page={$this->total}&{$this->argumetsOther}">尾页</a>"; break; } return $linkStyle; } } //调用的实例 /* header('Content-Type: text/html;charset=utf-8'); $array=array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"); $page= isset($_GET['page'])? $_GET['page'] : 1 ; $arrayPage = new PaginationArray($array,"5",$page); $r = $arrayPage->page(); foreach($r["source"] as $s){ echo $s.'<br />'; } echo $r["links"]; */ ?>
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php+mysql数据库操作入门教程》、《php+mysqli数据库程序设计技巧总结》、《php面向对象程序设计入门教程》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP网络编程技巧总结》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。