PHP text article pagination code example

WBOY
Release: 2016-07-25 09:05:14
Original
1560 people have browsed it
  1. /**
  2. ************************************************* **********
  3. * Read Me
  4. * Article paging
  5. *
  6. * The paging method can be paging by word count, paging by line breaks, paging by special marks, etc.
  7. * In fact, the implementation idea is the same, just use It is put into an array according to certain rules
  8. * and then a certain fragment can be obtained according to 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 to be paginated
  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. //Split by word count
  42. // $str = str_split($ data, $perpage);
  43. //Split 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 .= '< a href="?page=0">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 .= 'Last page';
  67. }
  68. }
  69. ?>
  70. Test article pagination

Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template