php的来帮忙看下代码

搬瓦工机场JMS

51jb上看来的一个代码
https://www.jb51.net/article/30530.htm
试了好几次,好像都不成功啊,$data和content内容输出不了

  1. <?php
  2. /**
  3. * **********************************************************
  4. * Read Me
  5. * 文章分页
  6. *
  7. * 分页方式,可以按字数分页,按换行分页,按特殊标记分页等
  8. * 其实实现思路是一样的,只是将其按一定规律放入一个数组
  9. * 然后根据 url 传入的参数取得某个片段即可
  10. * 大家完全可以写一个功能强大的函数保存起来以备不时之需
  11. *
  12. * 题外话:很多编辑器都有插入分页按钮,利用插入的代码可显示分页
  13. *
  14. * filename: page.php
  15. * charset: UTF-8
  16. * create date: 2012-5-16
  17. * **********************************************************
  18. * @author itbdw <[email protected]>
  19. * [url=home.php?mod=space&uid=7292]@Copyright[/url] (C) 2011-2012 itbdw
  20. * @link http://weibo.com/itbudaoweng
  21. */
  22. header(‘Content-Type:text/html; charset=utf-8’);
  23. ?>
  24. <?php
  25. $title = ‘Pagination Test’;
  26. //需要分页的数据
  27. $data = <<<DATA
  28. Hey, guys. I am here to test if it is working.
  29. This pagination is very simple, isn’t it?<!–pagination–>
  30. And I tried to use different method to page it.
  31. Can you see it?
  32. DATA;
  33. //当前文章页
  34. $page = 0;
  35. //初始文章长度
  36. $length = 0;
  37. //分页长度
  38. $perpage = 160;
  39. //显示在页面的代码
  40. $link = ”;
  41. //分割后的数组
  42. $strArr = array();
  43. $page = isset($_GET[‘page’]) ? intval($_GET[‘page’]) : 0;
  44. $length = strlen($data);
  45. //按字数分割
  46. // $str = str_split($data, $perpage);
  47. //按字符分割
  48. $delimiter = "\n";
  49. // $delimiter = ‘<–pagination–>’;
  50. $strArr = explode($delimiter, $data);
  51. $strNum = count($strArr);
  52. $content = $strArr[$page];
  53. if ($strNum > 1) {
  54. if ($page != 0) {
  55. $link .= ‘<a href="?page=0">首页</a>’;
  56. } else {
  57. $link .= ‘<span>首页</span>’;
  58. }
  59. for ($n = 0; $n < $strNum; $n++) {
  60. if ($n == $page) {
  61. $link .= ‘<span>’ . ($n + 1) . ‘</span>’;
  62. } else {
  63. $link .= "<a href=’?page={$n}’>" . ($n + 1) . "</a>";
  64. }
  65. }
  66. $link .= ”;
  67. if ($page != ($strNum – 1)) {
  68. $link .= "<a href=’?page=" . ($strNum – 1) . "’>尾页</a>";
  69. } else {
  70. $link .= ‘<span>尾页</span>’;
  71. }
  72. }
  73. ?>
  74. <!DOCTYPE HTML>
  75. <html lang="en-US">
  76. <head>
  77. <meta charset="UTF-8">
  78. <style type="text/css">
  79. body {
  80. font-family: ‘微软雅黑’;
  81. }
  82. .link a, span {
  83. margin: 1px;
  84. padding: 1px;
  85. }
  86. .link span {
  87. color: #777;
  88. }
  89. .link a {
  90. color: #26A2DA;
  91. text-decoration: none;
  92. }
  93. </style>
  94. <title>测试文章分页</title>
  95. </head>
  96. <body>
  97. <h1><?php echo $title; ?></h1>
  98. <p><?php echo $content; ?></p>
  99. <hr />
  100. <p class="link"><?php echo $link; ?></p>
  101. </body>
  102. </html>

复制代码

内蒙古网友:51jb?不错的域名
吉林网友:不懂啊,兄弟,来个大佬吧
黑龙江网友:。。。。。。。
山东网友:这代码没有什么问题
安徽网友:100 有偿帮解决,需要的话消息弹我。(明白人会知道我在帮楼主)
江西网友:跑了一下,没看出什么问题

未经允许不得转载:美国VPS_搬瓦工CN2 GIA VPS » php的来帮忙看下代码

赞 (0) 打赏

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏