Convenient and quick PHP long article paging function _ PHP Tutorial

Source: Internet
Author: User
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:

  1. <? Php
  2. Function ff_page ($ content, $ page)
  3. {
  4. Global $ expert_id;
  5. $ PageLength = 2000; // Number of words per page
  6. $ CLength = strlen ($ content );
  7. $ PageCount = floor ($ CLength
    /$ PageLength) + 1; // calculate the page number
  8. $ PageArray = array ();
  9. $ Seperator = array ("n ",
    "R ",". ","! ","? ",";
    "," "," '"); // Separator
  10. // Echo "page number:". $ PageCount. "<br> ";
  11. // Echo "length:". $ CLength. "<br> ";
  12. // The strpos () function returns a string in
    Position of the first occurrence of another string
  13. If ($ CLength <$ PageLength)
  14. {
  15. Echo $ content;
  16. } Else {
  17. $ PageArray [0] = 0;
  18. $ Pos = 0;
  19. $ I = 0;
  20. // Page 1
  21. For ($ j = 0; $ j <sizeof ($ Seperator); $ j ++)
  22. {
  23. // Echo $ Seperator [$ j];
  24. $ Pos = strpos ($ content,
    $ Seperator [$ j], $ PageArray [$ I] + 1900 );
  25. While ($ Pos> 0 & $ Pos
    <($ I + 1) * $ PageLength &&
    $ Pos> $ I * $ PageLength)
  26. {
  27. $ PageArray [$ I] = $ Pos;
  28. $ Pos = strpos ($ Pos + $ PageLength,
    $ Content, $ Seperator [$ j]);
  29. }
  30. If ($ PageArray [$ I]> 0)
  31. {
  32. $ J = $ j + sizeof ($ Seperator) + 1;
  33. }
  34. }
  35. //---
  36. For ($ I = 1; $ I <$ PageCount-1; $ I ++ ){
  37. For ($ j = 0; $ j <sizeof ($ Seperator); $ j ++)
  38. {
  39. // Echo $ Seperator [$ j];
  40. $ Pos = strpos ($ content, $ Seperator
    [$ J], $ PageArray [$ i-1] + 1900 );
  41. While ($ Pos> 0 & $ Pos <
    ($ I + 1) * $ PageLength & $ Pos>
    $ I * $ PageLength)
  42. {
  43. $ PageArray [$ I] = $ Pos;
  44. $ Pos = strpos ($ Pos + $ PageLength,
    $ Content, $ Seperator [$ j]);
  45. }
  46. If ($ PageArray [$ I]> 0)
  47. {
  48. $ J = $ j + sizeof ($ Seperator) + 1;
  49. }
  50. }
  51. }
  52. // -- PHP long article paging function last page
  53. $ PageArray [$ PageCount-1] = $ CLength;
  54. // $ Page = 2;
  55. If ($ page = 1)
  56. {
  57. $ Output = substr ($ content, 0,
    $ PageArray [$ page-1] + 2 );
  58. }
  59. If ($ page> 1 & $ page <= $ PageCount)
  60. {
  61. $ Output = substr ($ content, $ PageArray
    [$ Page-2] + 2, $ PageArray [$ page-1]-$
    PageArray [$ page-2]);
  62. $ Output = "(connected to the". ($ page-1). "page) n". $ output;
  63. }
  64. Echo str_replace ("n", "<br>
    ", $ Output );
  65. // If ($ page = $ PageCount)
  66. // Return $ output = substr ($ content,
    $ PageArray [$ page-2] + 2, $ PageArray [$ page-1]-$ PageArray [$ page-2]);
  67. If ($ PageCount> 1)
  68. {
  69. Echo "<br> <center> ";
  70. Echo"". $ Page." </font>/". $ PageCount." page ";
  71. If ($ page> 1)
  72. Echo "<a href = $ PHP_SELF? Expert_id = $ expert_id & page_t = ". ($ page-1)."> Previous page </a> ";
  73. Else
  74. Echo "previous page ";
  75. For ($ I = 1; $ I <= $ PageCount; $ I ++)
  76. {
  77. Echo "<a href = $ PHP_SELF? Expert_id = $ expert_id & page_t = ". $ I."> [". $ I."] </a> ";
  78. }
  79. If ($ page <$ PageCount)
  80. Echo "<a href = $ PHP_SELF? Expert_id = $ expert_id & page_t = ". ($ page + 1)."> Next page </a> ";
  81. Else
  82. Echo "next page ";
  83. Echo "</center> ";
  84. }
  85. }
  86. }?>

Use of paging functions for PHP long articles

 
 
  1. <? Php
  2. $ Content1 = ''test text,
    Try to be longer, www.corange.cn ";
  3. $ Current = $ _ REQUEST ['page _ t'];
  4. $ Result = ff_page
    ($ Content1, $ current );
  5. Echo $ result;
  6. ?>

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...

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.