Instance code:
Copy codeThe Code is as follows:
<? Php
/**
**************************************** *******************
* Read Me
* Article pagination
*
* Paging mode: Paging by words, line feed, and special mark
* In fact, the implementation idea is the same, just put it into an array according to a certain rule
* Obtain a part based on the parameters passed in by the url.
* You can write a powerful function to save it as needed.
*
* Digression: Many Editors Use the insert page button to display pages using the inserted code.
*
* Filename: page. php
* Charset: UTF-8
* Create date: 2012-5-16
**************************************** *******************
* @ Author itbdw <itbudaoweng@gmail.com>
* @ Copyright (C) 2011-2012 itbdw
* @ Link http://weibo.com/itbudaoweng
*/
Header ('content-Type: text/html; charset = UTF-8 ');
?>
<? Php
$ Title = 'pagination test ';
// The data to be paged
$ Data = <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 );
// Word Segmentation
// $ Str = str_split ($ data, $ perpage );
// Separate 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 </a> ';
} Else {
$ Link. = '<span> homepage </span> ';
}
For ($ n = 0; $ n <$ strNum; $ n ++ ){
If ($ n = $ page ){
$ Link. = '<span>'. ($ n + 1). '</span> ';
} Else {
$ Link. = "<a href = '? Page = {$ n} '> ". ($ n + 1)." </a> ";
}
}
$ Link. = '';
If ($ page! = ($ StrNum-1 )){
$ Link. = "<a href = '? Page = ". ($ strNum-1)." '> last page </a> ";
} Else {
$ Link. = '<span> last page </span> ';
}
}
?>
<! Doctype html>
<Html lang = "en-US">
<Head>
<Meta charset = "UTF-8">
<Style type = "text/css">
Body {
Font-family: ' ';
}
. Link a, span {
Margin: 1px;
Padding: 1px;
}
. Link span {
Color: #777;
}
. Link {
Color: # 26A2DA;
Text-decoration: none;
}
</Style>
<Title> test article page </title>
</Head>
<Body>
<H1> <? Php echo $ title;?> </H1>
<P> <? Php echo $ content;?> </P>
<Hr/>
<P class = "link"> <? Php echo $ link;?> </P>
</Body>
</Html>