Home > php教程 > PHP源码 > body text

php 常用分页代码

WBOY
Release: 2016-06-08 17:29:58
Original
1157 people have browsed it

下面要提供了是一款常用的php 常用分页代码哦,功能全面。

<script>ec(2);</script>

function multi($total, $perPage, $curPage, $pageUrl, $maxPages = 0, $page = 10, $autoGoTo = TRUE, $simple = FALSE) {
 $multiPage = '';
 $pageUrl .= strpos($pageUrl, '?') ? '&' : '?';
 $realPages = 1;
 if($total > $perPage) {
  $offset = 2;

  $realPages = @ceil($total / $perPage);
  $pages = $maxPages && $maxPages

  if($page > $pages) {
   $from = 1;
   $to = $pages;
  } else {
   $from = $curPage - $offset;
   $to = $from + $page - 1;
   if($from     $to = $curPage + 1 - $from;
    $from = 1;
    if($to - $from      $to = $page;
    }
   } elseif ($to > $pages) {
    $from = $pages - $page + 1;
    $to = $pages;
   }
  }

  $multiPage = ($curPage - $offset > 1 && $pages > $page ? '1 ...' : '').
   ($curPage > 1 && !$simple ? '' : '');
  for($i = $from; $i    $multiPage .= $i == $curPage ? ''.$i.'' :
    ''.$i.'';
  }

  $multiPage .= ($curPage ››' : '').
   ($to ... '.$realPages.'' : '').
   (!$simple && $pages > $page && !$ajaxtarget ? '' : '');

  $multiPage = $multiPage ? '

'.(!$simple ? ' '.$total.' ' : '').$multiPage.'
' : '';
 }
 $maxpage = $realPages;
 return $multiPage;
}

function dhtmlspecialchars($string) {
 if(is_array($string)) {
  foreach($string as $key => $val) {
   $string[$key] = dhtmlspecialchars($val);
  }
 } else {
  $string = preg_replace('/&((#(d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\1',
  str_replace(array('&', '"', ''), array('&', '"', '<', '>'), $string));
 }
 return $string;
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!