Instance code:
Copy CodeThe code is as follows:
/**
* **********************************************************
* Read Me
* Article pagination
*
* Paging method, can be paged by the number of words, according to line breaks, according to special marks, such as paging
* In fact, the realization of the idea is the same, just put it into an array according to certain rules
* Then get a fragment based on the parameters passed in the URL
* You can write a powerful function to save it for a rainy future.
*
* Aside: Many editors have insert paging buttons that can be used to display pagination using the inserted code
*
* filename:page.php
* Charset:utf-8
* Create date:2012-5-16
* **********************************************************
* @author ITBDW
* @copyright (C) 2011-2012 ITBDW
* @link Http://weibo.com/itbudaoweng
*/
Header (' content-type:text/html; Charset=utf-8 ');
?>
$title = ' pagination Test ';
Data that needs paging
$data = << Hey, guys. I am here-to-test if it is working.
This pagination was very simple, isn ' t it?
And I tried to the use of different method to page it.
Can you see it?
DATA;
Current article page
$page = 0;
Initial article length
$length = 0;
Paging length
$perpage = 160;
Code that appears on the page
$link = ";
The segmented array
$STRARR = Array ();
$page = isset ($_get[' page ')? Intval ($_get[' page '): 0;
$length = strlen ($data);
Split by word
$str = Str_split ($data, $perpage);
Split by character
$delimiter = "\ n";
$delimiter = ' <--pagination--> ';
$STRARR = Explode ($delimiter, $data);
$strNum = count ($STRARR);
$content = $STRARR [$page];
if ($strNum > 1) {
if ($page! = 0) {
$link. = ' Home ';
} else {
$link. = 'Home Page';
}
for ($n = 0; $n < $strNum; $n + +) {
if ($n = = $page) {
$link. = '' . ($n + 1). '';
} else {
$link. = "". ($n + 1). "";
}
}
$link. = ';
if ($page! = ($strNum-1)) {
$link. = "Last";
} else {
$link. = 'last page';
}
}
?>
<title>Test article pagination</title>