PHP text article pagination code _php instances by tag or length (no database involved)

Source: Internet
Author: User
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>








  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.