PHP long article paging function-PHP source code

Source: Internet
Author: User
Ec (2); & lt ;? Phpfunctionff_page ($ content, $ page) {global $ expert_id; $ PageLength2000; Number of words per page $ CLengthstrlen ($ content); $ PageCountfloor ($ CLength $ PageLength) + 1; page number calculation $ PageAr script ec (2); script

{
Global $ expert_id;
$ PageLength = 2000; // Number of words per page
$ CLength = strlen ($ content );
$ PageCount = floor ($ CLength/$ PageLength) + 1; // calculate the page number
$ PageArray = array ();
$ Seperator = array ("n", "r ",". ","! ","? ","; "," "," '"); // Separator
// Echo "page number:". $ PageCount ."
";
// Echo "Length:". $ CLength ."


";
// The strpos () function returns the position where the string first appears in another string.
If ($ CLength <$ PageLength)
{
Echo $ content;
} Else {
$ PageArray [0] = 0;
$ Pos = 0;
$ I = 0;
// Page 1
For ($ j = 0; $ 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
{
// 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;
}
}
}

// -- Last page
$ 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 = "(connected to the". ($ page-1). "page) n". $ output;
}
Echo str_replace ("n ","
", $ Output );
// If ($ page = $ PageCount)
// Return $ output = substr ($ content, $ PageArray [$ page-2] + 2, $ PageArray [$ page-1]-$ PageArray [$ page-2]);
If ($ PageCount> 1)
{
Echo"


";
Echo "". $ page. "/". $ PageCount. "page ";
If ($ page> 1)
Echo "Previous Page ";
Else
Echo "Previous Page ";
For ($ I = 1; $ I <= $ PageCount; $ I ++)
{
Echo "[". $ I. "]";
}
If ($ page <$ PageCount)
Echo "next page ";
Else
Echo "next page ";
Echo" ";
}
}
}?>

$ Content1 = ''test text, which should be as long as possible, www.111cn.net ";
$ Current = $ _ REQUEST ['page _ T'];
$ Result = ff_page ($ content1, $ current );
Echo $ result;
?>

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.