Home php教程 php手册 php 文章内容分页代码

php 文章内容分页代码

Jun 13, 2016 am 11:24 AM
php code content point Pagination insert article yes of editor

php 文章内容分页代码,是根据由编辑器插入的分页符来操作了,我们可以分出超漂亮的偏移效果的分页。文章内容分页文章内容分页

php教程 文章内容分页代码,是根据由编辑器插入的分页符来操作了,我们可以分出超漂亮的偏移效果的分页。
文章内容分页
文章内容分页
 * author:陈凯
 * data:2010-09-15
 * 文章分页类
 */

class contentpage
{
 private $content;  //文章内容
 private $pagesize;    //每页最少字节数
 private $breakflag;  //分页符(可以自定义,默认为n)
 private $pageurl;  //url地址
 private $pagevar;  //分页参数
 public  $pagecount;  //总页数
 public  $page;   //当前页码
 public  $pagebreak;  //每页起始位置

 function __construct($content = "",$pagesize = 10,$breakflag ="n",$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;$kpagesize;$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)    {
    $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] 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 = "上一页  ";
  }

  //输出数字页码
  for($j=1;$jpagecount;$j++)
  {
   if($j == $this->page)
   {
    $pagenav .= "".$j."  ";
   }
   else
   {
    $pagenav .= "".$j."  ";
   }
  }
  //下一页
  if($this->page pagecount && $this->pagecount >1)
  {
   $pagenav .= "下一页  ";
  }
  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(); //输出页码
?>

-->


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

See all articles