PHP implements page-class _php techniques for file content operations

Source: Internet
Author: User
Tags learn php learn php programming php class php programming

This example of this article for you to share the PHP implementation of file content operation of the paging class, emphasize the file only for the operation, for your reference, the specific content as follows

<?php class Strpage {private $current;  Current page private $file;  Operation File Private $totalPage;  Total number of pages private $url;  The parameters passed are private $pageLen;
 The length of the display on each page function __construct ($file, $len =) {$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 ();
 //Get to the total length of this file private function Gettotalpage () {return ceil (strlen ($this->file)/$this->pagelen);
 //Gets the currently passed parameter, retains the parameter, 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 Private Function First () {if ($this->current>1) return "<a href=". $this->url. "
 1 ' > Home </a> '; //Previous Private Function pre () {if ($this->current > 1) return "<a href= ' ". $this->url. ($this->current-1). "'
 > Prev </a> "; //Next page Private function next () {if ($this->current < $this->totalpage) return "<a href=". $this->url. ($this->current+1). "'
 > next page </a> "; //Last page Private Function end () {if ($this->current < $this->totalpage) return "<a href=". $this->url . $this->totalpage. "'
 > Last </a> ";
 The Public Function pagelist () {$pageListStr = '; For ($i =1 $i <= $this->totalpage; $i + +) {if ($i = = $this->current) {$pageListStr. = "<span style=" font-size : 20px;color: #f00 ' > '. $i. "
  </span>  "; }else{$pageListStr. = "<a href=". $this->url. $i. "' > ". $i."
   </a> ";
 } return $PAGELISTSTR; The 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  The Public Function getcontents () {$prePageLen = strlen ($this->substrs ($this->current-1));
 $currentPageLen = strlen ($this->substrs ($this->current));
 Return substr ($this->file, $prePageLen, $currentPageLen-$prePageLen);
  The 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; }
 
}

Wonderful topic sharing:PHP paging function Operation

The above is the entire content of this article, I hope that you learn PHP programming help.

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.