PHP text article paging code by tag or length (no database involved) _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP text article paging code by tag or length (does not involve databases ). Example code: Copy the code as follows :? Php *************************************** * ********************** ReadMe * article paging ** by page, you can paging by words and by instance code:

The code is as follows:


/**
**************************************** *******************
* 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
* @ Copyright (C) 2011-2012 itbdw
* @ Link http://weibo.com/itbudaoweng
*/
Header ('content-Type: text/html; charset = utf-8 ');
?>
$ Title = 'pagination test ';
// The data to be paged
$ 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 );
// 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. = '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. = 'end page ';
}
}
?>





Test article page








The pipeline code is as follows :? Php /************************************** * *********************** Read Me * article paging ** by page, you can paging by words,...

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.