Convenient and quick PHP long article paging function. Today, we have written a PHP long article paging function for you to easily compile your code :? Phpfunctionff_page ($ content, $ page) {global $ expert_id; $ PageLength2000; word per page
Today, we have written a PHP long article paging function for you to easily compile your code:
- <? Php
- Function ff_page ($ content, $ page)
- {
- 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. "<br> ";
- // Echo "length:". $ CLength. "<br> ";
- // The strpos () function returns a string in
Position of the first occurrence of another string
- If ($ CLength <$ PageLength)
- {
- Echo $ content;
- } Else {
- $ PageArray [0] = 0;
- $ Pos = 0;
- $ I = 0;
- // Page 1
- For ($ j = 0; $ j <sizeof ($ Seperator); $ 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 <sizeof ($ Seperator); $ 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;
- }
- }
- }
- // -- PHP long article paging function 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", "<br>
", $ Output );
- // If ($ page = $ PageCount)
- // Return $ output = substr ($ content,
$ PageArray [$ page-2] + 2, $ PageArray [$ page-1]-$ PageArray [$ page-2]);
- If ($ PageCount> 1)
- {
- Echo "<br> <center> ";
- Echo"". $ Page." </font>/". $ PageCount." page ";
- If ($ page> 1)
- Echo "<a href = $ PHP_SELF? Expert_id = $ expert_id & page_t = ". ($ page-1)."> Previous page </a> ";
- Else
- Echo "previous page ";
- For ($ I = 1; $ I <= $ PageCount; $ I ++)
- {
- Echo "<a href = $ PHP_SELF? Expert_id = $ expert_id & page_t = ". $ I."> [". $ I."] </a> ";
- }
- If ($ page <$ PageCount)
- Echo "<a href = $ PHP_SELF? Expert_id = $ expert_id & page_t = ". ($ page + 1)."> Next page </a> ";
- Else
- Echo "next page ";
- Echo "</center> ";
- }
- }
- }?>
Use of paging functions for PHP long articles
- <? Php
- $ Content1 = ''test text,
Try to be longer, www.corange.cn ";
- $ Current = $ _ REQUEST ['page _ t'];
- $ Result = ff_page
($ Content1, $ current );
- Echo $ result;
- ?>
The code example for the use and implementation of the paging function in PHP is shown above.
Why :? Php functionff_page ($ content, $ page) {global $ expert_id; $ PageLength = 2000; // word per page...