PHP Text article pagination code example

Source: Internet
Author: User
  1. /**
  2. * **********************************************************
  3. * Read Me
  4. * Article pagination
  5. *
  6. * Paging method, can be paged by the number of words, according to line breaks, according to special marks, such as paging
  7. * In fact, the realization of the idea is the same, just put it into an array according to certain rules
  8. * Then get a fragment based on the parameters passed in 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. Data that needs paging
  24. $data = <<
  25. Hey, guys. I am here-to-test if it is working.
  26. This pagination was very simple, isn ' t it?
  27. And I tried to the use of different method to page it.
  28. Can you see it?
  29. DATA;
  30. Current article page
  31. $page = 0;
  32. Initial article length
  33. $length = 0;
  34. Paging length
  35. $perpage = 160;
  36. Code that appears on the page
  37. $link = ";
  38. The segmented array
  39. $STRARR = Array ();
  40. $page = isset ($_get[' page ')? Intval ($_get[' page '): 0;
  41. $length = strlen ($data);
  42. Split by word
  43. $str = Str_split ($data, $perpage);
  44. Split by character
  45. $delimiter = "\ n";
  46. $delimiter = ' <--pagination--> ';
  47. $STRARR = Explode ($delimiter, $data);
  48. $strNum = count ($STRARR);
  49. $content = $STRARR [$page];
  50. if ($strNum > 1) {
  51. if ($page! = 0) {
  52. $link. = ' Home ';
  53. } else {
  54. $link. = ' home ';
  55. }
  56. for ($n = 0; $n < $strNum; $n + +) {
  57. if ($n = = $page) {
  58. $link. = '. ($n + 1). '';
  59. } else {
  60. $link. = "". ($n + 1). "";
  61. }
  62. }
  63. $link. = ';
  64. if ($page! = ($strNum-1)) {
  65. $link. = "Last";
  66. } else {
  67. $link. = ' last ';
  68. }
  69. }
  70. ?>
  71. Test article pagination
Copy Code
  • 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.