php 文章内容分页代码
发布:smiling 来源: PHP粉丝网 添加日期:2014-09-09 11:29:40 浏览: 评论:0
php文章内容分页代码,是根据由编辑器插入的分页符来操作了,我们可以分出超漂亮的偏移效果的分页,代码如下:
- * author:陈凯
- * data:2010-09-15
- * 文章分页类
- */
- class contentpage
- {
- private $content; //文章内容
- private $pagesize; //每页最少字节数
- private $breakflag; //分页符(可以自定义,默认为)
- private $pageurl; //url地址
- private $pagevar; //分页参数
- public $pagecount; //总页数
- public $page; //当前页码
- public $pagebreak; //每页起始位置
- function __construct($content = "",$pagesize = 10,$breakflag =" ",$pageurl = '',$pagevar = 'p')
- {
- $this->content = $content;
- $this->pagesize = $pagesize;
- $this->breakflag = $breakflag;
- $this->pageurl = $pageurl;
- $this->pagevar = $pagevar;
- $this->getpages();
- }
- //总页数,每页的起始位置和结束位置
- public function getpages()
- {
- $contentlen = strlen($this->content); //文章总字节数
- $this->pagebreak[0] = 0;
- $i = 0;
- $offset = $this->pagesize;
- for ($k=0;$k<$contentlen/$this->pagesize;$k++)
- {
- if($offset > $contentlen)
- {
- $i++;
- $this->pagebreak[$i] = $contentlen;
- break;
- }
- //查找$this->pagevar出现的位置
- $where = strpos($this->content,$this->breakflag,$offset);
- if($where > $contentlen or intval($where) < 1)
- {
- $i++;
- $this->pagebreak[$i] = $contentlen;
- break;
- }
- else
- {
- $i++;
- $this->pagebreak[$i] = $where;
- $offset = $where + $this->pagesize;
- }
- }
- $this->pagecount = $i;
- if(isset($_get[$this->pagevar]) && $_get[$this->pagevar] >1 && $_get[$this->pagevar] <= $this->pagecount)
- {
- $this->page = $_get[$this->pagevar];
- }
- else
- {
- $this->page = 1;
- }
- }
- //每页内容
- function getpage()
- {
- //截取当前页码的数据
- if($this->page > 1)
- {
- return substr($this->content,$this->pagebreak[$this->page-1]+1,$this->pagebreak[$this->page] - $this->pagebreak[$this->page-1]);
- }
- else
- {
- return substr($this->content,$this->pagebreak[$this->page-1],$this->pagebreak[$this->page] - $this->pagebreak[$this->page-1]);
- }
- }
- //分页条
- public function getpagenav()
- {
- if($this->page > 1)
- {
- $pagenav = "<a href='".$this->geturl()."=".($this->page-1)."' class='div'>上一页</a> ";
- }
- //输出数字页码
- for($j=1;$j<=$this->pagecount;$j++)
- {
- if($j == $this->page)
- {
- $pagenav .= "<span class='divsi'>".$j."</span> ";
- }
- else
- {
- $pagenav .= "<a href='".$this->geturl()."=".$j."' class='div'>".$j."</a> ";
- }
- }
- //下一页
- if($this->page < $this->pagecount && $this->pagecount >1)
- {
- $pagenav .= "<a href='".$this->geturl()."=".($this->page+1)."' class='div'>下一页</a> ";
- }
- return $pagenav;
- }
- //获取url地址
- public function geturl()
- {
- $url = $_server['request_uri'];
- $parse_url = parse_url($url);
- $query_url = $parse_url['query'];
- if($query_url)
- {
- $query_url = ereg_replace("(^|&)".$this->pagevar."=".$this->page,"",$query_url);
- $url = str_replace($parse_url['query'],$query_url,$url);
- if($query_url)
- {
- $url .= "&".$this->pagevar;
- }
- else
- {
- $url .= $this->pagevar;
- }
- }
- else
- {
- $url .= "?".$this->pagevar;
- }
- return $url;
- }
- }
- $content = "第一页:文章内容分页阿斯顿浪费空间阿斯顿来看福建省地方吉林省福建路口附近大手拉飞机上浪费的说浪费监理费
- 第二页:阿斯顿房间阿双方了解啊对萨拉开发记得谁来付款将令对方空间的来福建阿里是否
- 第三页:欧文炯诶哦生地拉开方面来看就继续超文章内容分页滤机蓝卡
- 第四页:欧文日据拉萨及发动四分啊就双方的将爱是发觉是文章内容分页否了。";
- $model = new contentpage($content);
- echo $model->getpage(); //输出分页内容
- echo $model->getpagenav(); //输出页码
- ?>
- <style type="text/css教程">
- <!--
- body {
- width:800px;
- margin:0 auto;
- margin-top:50px;
- font-size:12px;
- }
- a {
- color:#014ccc;
- text-decoration:none;
- }
- .div {
- float:left;
- cursor:pointer;
- font-weight:bold;
- margin-right:5px;
- display: block;
- padding:3px 7px;
- text-align:center;
- border:#bbdded solid 1px;
- }
- .divs {
- float:left;
- font-weight:bold;
- margin-right:5px;
- display: block;
- padding:3px 7px;
- text-align:center;
- border:#cccccc solid 1px;
- }
- .divsi {
- float:left;
- font-weight:bold;
- margin-right:5px;
- display: block;
- padding:3px 7px;
- text-align:center;
- background:#3399ff;
- color:#ffffff;
- border:#cccccc solid 1px;
- }//开源代码phpfensi.com
- .div:hover {
- background:#3399ff;
- color:#ffffff;
- }
- .divsi:hover {
- background:#3399ff;
- color:#ffffff;
- }
- -->
- </style>
Tags: php文章内容分页 php文章分页
- 上一篇:Page分页函数
- 下一篇:php 经典的分页代码类
相关文章
- ·深入分析PHP文章内容分页(2015-04-11)
- ·PHP长文章分页的示例(2016-08-25)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)