Php text article paging code example

Source: Internet
Author: User
Php text article paging code example

  1. /**
  2. **************************************** *******************
  3. * Read Me
  4. * Article pagination
  5. *
  6. * Paging mode: Paging by words, line feed, and special mark
  7. * In fact, the implementation idea is the same, just put it into an array according to a certain rule
  8. * Obtain a part based on the parameters passed in by the url.
  9. *
  10. *
  11. * Filename: page. php
  12. * Charset: UTF-8
  13. * Create date: 2012-5-16
  14. **************************************** *******************
  15. * @ Author itbdw
  16. * @ Copyright (C) 2011-2012 itbdw
  17. * @ Link http://weibo.com/itbudaoweng
  18. * @ Url http://bbs.it-home.org
  19. */
  20. Header ('content-Type: text/html; charset = utf-8 ');
  21. ?>
  22. $ Title = 'pagination test ';
  23. // The data to be paged
  24. $ Data = <Hey, guys. I am here to test if it is working.
  25. This pagination is very simple, isn' t it?
  26. And I tried to use different method to page it.
  27. Can you see it?
  28. DATA;
  29. // Current article page
  30. $ Page = 0;
  31. // Initial article length
  32. $ Length = 0;
  33. // Page length
  34. $ Perpage = 160;
  35. // Code displayed on the page
  36. $ Link = '';
  37. // Split array
  38. $ StrArr = array ();
  39. $ Page = isset ($ _ GET ['Page'])? Intval ($ _ GET ['Page']): 0;
  40. $ Length = strlen ($ data );
  41. // Word segmentation
  42. // $ Str = str_split ($ data, $ perpage );
  43. // Separate by characters
  44. $ Delimiter = "\ n ";
  45. // $ Delimiter = '<-- pagination --> ';
  46. $ StrArr = explode ($ delimiter, $ data );
  47. $ StrNum = count ($ strArr );
  48. $ Content = $ strArr [$ page];
  49. If ($ strNum> 1 ){
  50. If ($ page! = 0 ){
  51. $ Link. = 'homepage ';
  52. } Else {
  53. $ Link. = 'homepage ';
  54. }
  55. For ($ n = 0; $ n <$ strNum; $ n ++ ){
  56. If ($ n = $ page ){
  57. $ Link. = ''. ($ n + 1 ).'';
  58. } Else {
  59. $ Link. = "". ($ n + 1 )."";
  60. }
  61. }
  62. $ Link. = '';
  63. If ($ page! = ($ StrNum-1 )){
  64. $ Link. = "Last page ";
  65. } Else {
  66. $ Link. = 'end page ';
  67. }
  68. }
  69. ?>
  70. Test article 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.