PHP text article pagination code example
Release: 2016-07-25 09:05:14
Original
1560 people have browsed it
-
- /**
- ************************************************* **********
- * Read Me
- * Article paging
- *
- * The paging method can be paging by word count, paging by line breaks, paging by special marks, etc.
- * In fact, the implementation idea is the same, just use It is put into an array according to certain rules
- * and then a certain fragment can be obtained according to the parameters passed in the url
- *
- *
- * filename: page.php
- * charset: UTF-8
- * create date: 2012-5- 16
- * ************************************************* *************
- * @author itbdw
- * @copyright (C) 2011-2012 itbdw
- * @link http://weibo.com/itbudaoweng
- * @url http://bbs.it-home.org
- */
- header('Content-Type:text/html; charset=utf-8');
- ?>
- $title = 'Pagination Test';
- //Data that needs to be paginated
- $data = <<Hey, guys. I am here to test if it is working.
- This pagination is very simple, isn't it ?
- And I tried to use different method to page it.
- Can you see it?
- DATA;
- //Current article page
- $page = 0;
- //Initial article length
- $length = 0;
- //Page length
- $perpage = 160;
- //Code displayed on the page
- $link = '';
- //Split array
- $strArr = array();
- $page = isset($_GET['page']) ? intval($_GET['page']) : 0;
- $length = strlen($data);
- //Split by word count
- // $str = str_split($ data, $perpage);
- //Split by characters
- $delimiter = "n";
- // $delimiter = '<--pagination-->';
- $strArr = explode($delimiter, $data) ;
- $strNum = count($strArr);
- $content = $strArr[$page];
- if ($strNum > 1) {
- if ($page != 0) {
- $link .= '< a href="?page=0">Homepage';
- } else {
- $link .= 'Homepage';
- }
- for ($n = 0 ; $n < $strNum; $n++) {
- if ($n == $page) {
- $link .= '' . ($n + 1) . '';
- } else {
- $link .= "" . ($n + 1) . "";
- }
- }
- $link .= '';
- if ($page != ($strNum - 1)) {
- $link .= "Last page ";
- } else {
- $link .= 'Last page';
- }
- }
- ?>
-
-
-
-
-
- Test article pagination
-
-
-
-
php echo $link; ?>
-
Copy code
|
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31