/**
* ********************************************** ************
* Read Me
* Article pagination
*
* Pagination method, you can paginate by word count, paginate by line feed, paginate by special mark, etc.
* In fact, the implementation idea is the same, just put it into an array according to certain rules
* and then get a certain fragment according to the parameters passed in the url
* You can write a powerful function Save it for emergencies
*
* Off topic: Many editors have insert pagination buttons, and you can use the inserted code to display pagination
*
* 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 pagination
$data = <<Hey, guys. I am here to test if it is working.
This pagination is very simple, isn't it?< ;!--pagination-->
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 character
$ 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 .= '';
}
}
?>
Test article paging< ;/title>
< ;?php echo $content; ?>
< /p>