The PHP implementation applies to paging classes for file content operations. _ PHP Tutorial

Source: Internet
Author: User
Tags learn php programming
The PHP implementation applies to paging classes for file content operations ,. The PHP implementation applies to the paging class for file content operations. in this article, we will share with you the paging class for PHP to implement file content operations. we will emphasize that only file operations are available for your reference, use PHP to implement paging classes suitable for file content operations,

The examples in this article share with you the pagination class for PHP to implement file content operations, emphasizing that only file operations are available for your reference. the specific content is as follows:

<? Php class StrPage {private $ current; // The current page is private $ file; // The Operation file is private $ totalPage; // The total number of pages is private $ url; // The passed parameter private $ pageLen; // The length of function _ construct ($ file, $ len = 200) displayed on each page) {$ this-> file = file_get_contents ($ file); $ this-> pageLen = $ len; $ this-> current = isset ($ _ GET ['Page'])? $ _ GET ['Page']: 1; $ this-> totalPage = $ this-> getTotalPage (); $ this-> url = $ this-> getUrl ();} // obtain the total length of this file. private function getTotalPage () {return ceil (strlen ($ this-> file)/$ this-> pageLen );} // Obtain the currently passed parameter, retain the parameter, and the page parameter dynamically changes. private function getUrl () {$ url = parse_url ($ _ SERVER ['request _ URI ']); parse_str ($ url ['query'], $ queryArr); unset ($ queryArr ['Page']); $ queryStr = http_build_query ($ queryArr); return $ url ['Path']. '? '. $ QueryStr. '& page =';} // home page private function first () {if ($ this-> current> 1) return "url. "1 '> homepage";} // Previous Page private function pre () {if ($ this-> current> 1) return "url. ($ this-> current-1 ). "'> Previous Page";} // next Page private function next () {if ($ this-> current <$ this-> totalPage) return "url. ($ this-> current + 1 ). "'> next page";} // private function end () {if ($ this-> current <$ this-> totalPage) return "url. $ this-> totalPage. "'> last page";} public function pageList () {$ pageListStr = ''; for ($ I = 1; $ I <= $ this-> totalPage; $ I ++) {if ($ I ==$ this-> current) {$ pageListStr. = "". $ I. "";} else {$ pageListStr. = "url. $ I. "'> ". $ I. "" ;}} return $ pageListStr;} public function pageStyle ($ style = 1) {switch ($ style) {case 1: return "total ". $ this-> totalPage. "page ". $ this-> first (). $ this-> pre (). $ this-> pageList (). $ this-> next (). $ this-> end (); break; case 2; return $ this-> pageList (); break;} public function getContents () {$ prePageLen = strlen ($ this-> subStrs ($ this-> current-1 )); $ currentPageLen = strlen ($ this-> subStrs ($ this-> current); return substr ($ this-> file, $ prePageLen, $ currentPageLen-$ prePageLen );} public function subStrs ($ page) {$ string = ''; $ len = $ page * $ this-> pageLen; for ($ I = 0; $ I <$ len; $ I ++) {if (ord (substr ($ this-> file, $ I, 1)> 0xa0) {$ string. = substr ($ this-> file, $ I, 3); $ I = $ I + 2;} else {$ string. = substr ($ this-> file, $ I, 1) ;}} return $ string ;}}

Highlights: php paging operations

The above is all the content of this article. I hope it will help you learn PHP programming.

Examples in this article share with you the pagination class for PHP to implement file content operations, emphasizing that only file operations are available for your reference,...

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.