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;
?>