Pagination code of php article content

Source: Internet
Author: User

The pagination code of the php article content is operated based on the pagination characters inserted by the editor. We can split the pages with ultra-beautiful offset effects. Article content paging article content Paging

The pagination code of the php document content is operated based on the pagination characters inserted by the editor. We can split the pages with extremely beautiful offset effects.
Pagination of article content
Pagination of article content
* Author: Chen Kai
* Data: 2010-09-15
* Article Paging
*/

Class contentpage
{
Private $ content; // document content
Private $ pagesize; // minimum number of bytes per page
Private $ breakflag; // Page Break (customizable, default: n)
Private $ pageurl; // url
Private $ pagevar; // page Parameters
Public $ pagecount; // the total number of pages.
Public $ page; // the current page number.
Public $ pagebreak; // start position of each page

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 ();
}

// Total number of pages, start position and end position of each page
Public function getpages ()
{
$ Contentlen = strlen ($ this-> content); // The 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 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 on each page
Function getpage ()
{
// Truncate the data of 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 = "<a href = '". $ this-> geturl (). "= ". ($ this-> page-1 ). "'class = 'div '> previous page </a> & nbsp ;";
}

// Output the number page number
For ($ j = 1; $ j <= $ this-> pagecount; $ j ++)
{
If ($ j = $ this-> page)
{
$ Pagenav. = "<span class = 'divsi'>". $ j. "</span> & nbsp ;";
}
Else
{
$ Pagenav. = "<a href = '". $ this-> geturl (). "= ". $ j. "'class = 'div '> ". $ j. "</a> & nbsp ;";
}
}
// Next page
If ($ this-> page <$ this-> pagecount & $ this-> pagecount> 1)
{
$ Pagenav. = "<a href = '". $ this-> geturl (). "= ". ($ this-> page + 1 ). "'class = 'div '> next page </a> & nbsp ;";
}
Return $ pagenav;
}
// Obtain the 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 = "Page 1: The article content is displayed in pages. Aston is a waste of space. Aston is a waste of supervision fees.
Page 2: Aston room. Both parties know. For saradevelopment, remember who will make the payment so that the other party's space will come to Fujian and Alibaba?
Page 3
Page 4: Irwin detected that the content of the article is not displayed on pages according to Lhasa and launched by both parties. ";
$ Model = new contentpage ($ content );
Echo $ model-> getpage (); // output the page content
Echo $ model-> getpagenav (); // output page number
?>

<Style type = "text/css tutorial">
<! --
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;
}
. Div: hover {
Background: # 3399ff;
Color: # ffffff;
}
. Divsi: hover {
Background: # 3399ff;
Color: # ffffff;
}

-->
</Style>


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.