php简单分页类|page.class.php
简单好用的PHP分页类
<?php /** * page.class.php 分页类 * 日期:2015-04-05 * http://aowana.sinaapp.com */ class page { public static $url; public static $page; public static $total; public static $size; public static $number; public static $max; public static $action = array('previous', 'number', 'next'); public static function show($url, $page, $total, $size=10, $number=11) { self::$url = $url; self::$page = $page; self::$total = $total; self::$size = $size; self::$number = $number; self::$max = ceil($total / $size); $str = ''; foreach (self::$action as $name) $str .= self::$name(); return $str; } public static function first() { if (self::$page > 2) { $url = self::url(1); return "<li id=\"pbfirst\"><a href=\"{$url}\" title=\"首页\">首页</a></li>"; } } public static function previous() { if (self::$page > 1) { $url = self::url(self::$page - 1); return "<li id=\"pbprevious\"><a href=\"{$url}\" title=\"上一页\">上一页</a></li>"; } } public static function number() { $str = ''; $f = self::$number % 2 ? (self::$number - 1) / 2 : self::$number / 2; $s = self::$page - $f; $e = self::$page + $f; if (self::$page < ($f + 1)) { $s = 1; $e = self::$number; $e = $e > self::$max ? self::$max : $e; } if (self::$page > (self::$max - $f)) { $s = self::$max - self::$number; $s = $s < 1 ? 1 : $s; $e = self::$max; } for ($i=$s; $i<=$e; $i++) { $url = self::url($i); if ($i == self::$page) $str .= "<li><strong>{$i}</strong></li>"; else $str .= "<li><a href=\"{$url}\" title=\"第{$i}页\">{$i}</a></li>"; } return $str; } public static function next() { if (self::$page < self::$max) { $url = self::url(self::$page + 1); return "<li id=\"pbnext\"><a href=\"{$url}\" title=\"下一页\">下一页</a></li>"; } } public static function end() { if ((self::$max - self::$page) > 1) { $url = self::url(self::$max); return "<li id=\"pbend\"><a href=\"{$url}\" title=\"末页\">末页</a></li>"; } } public static function url($page) { return str_replace('{page}', $page, self::$url); } }
Copy after login
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks ago
By DDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
CakePHP Tutorial
1379
52

