-
- /**
- ************************************************* **********
- * 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
|