PHP article content paging Code _php tutorial

Source: Internet
Author: User
PHP article content paging code, is based on the page break inserted by the editor to operate, we can divide the beautiful offset effect of pagination. Article content pagination article content page

PHP Tutorial article content page code, is based on the page break inserted by the editor to operate, we can divide the beautiful offset effect of pagination.
Article content pagination
Article content pagination
* Author: Chen Kai
* DATA:2010-09-15
* Article pagination Class
*/

Class Contentpage
{
Private $content; Article content
Private $pagesize; Minimum number of bytes per page
Private $breakflag; Page break (can be customized, default is N)
Private $pageurl; URL address
Private $pagevar; Paging parameters
Public $pagecount; Total pages
Public $page; Current page number
Public $pagebreak; Start position per page

function __construct ($content = "", $pagesize = ten, $breakflag = "n", $pageurl = ", $pagevar = ' P ')
{
$this->content = $content;
$this->pagesize = $pagesize;
$this->breakflag = $breakflag;
$this->pageurl = $pageurl;
$this->pagevar = $pagevar;
$this->getpages ();
}

Total pages, starting and ending positions for each page
Public Function GetPages ()
{
$contentlen = strlen ($this->content); Total number of bytes in the article
$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
}
Find the location where the $this->pagevar appears
$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;
}
}

Content per page
function GetPage ()
{
Intercept data for the current page number
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]);
}

}

Pagination Bar
Public Function Getpagenav ()
{
if ($this->page > 1)
{
$pagenav = "Geturl ()." =". ($this->page-1). "' class= ' div ' > prev ';
}

Output Digital Page number
for ($j =1; $j <= $this->pagecount; $j + +)
{
if ($j = = $this->page)
{
$pagenav. = "". $j."";
}
Else
{
$pagenav. = "Geturl ()." = ". $j." ' class= ' div ' > '. $j. ' ";
}
}
Next page
if ($this->page < $this->pagecount && $this->pagecount >1)
{
$pagenav. = "Geturl ()." =". ($this->page+1). "' class= ' div ' > next page ";
}
return $pagenav;
}
Get URL Address
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 = "First page: article content page Aston wasted space Aston, Fujian province, Jilin Province, Fujian Road, near the mouth of the large hand-drawn aircraft waste supervision costs
second page: Aston Room a mutual understanding ah to Sara development remember who to pay will be the other side of the space to Fujian Ali whether
The third page: Owen ah oh, look at the field to continue the Super Article content page filter Blue Card
Fourth: Owenzhi according to Lhasa and launched four points ah on both sides will love is found to be the content of the article page No. ";
$model = new Contentpage ($content);
Echo $model->getpage ();//Output paging content
Echo $model->getpagenav ();//output page number
?


http://www.bkjia.com/PHPjc/444849.html www.bkjia.com true http://www.bkjia.com/PHPjc/444849.html techarticle PHP article content paging code, is based on the page break inserted by the editor to operate, we can divide the beautiful offset effect of pagination. Article content pagination article content page PHP tutorial ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.