本文实例为大家分享了php实现可自定义样式的分页类,供大家参考,具体内容如下
标签 总体样式
* @param string $PageUrl 当前页样式
* @param number $PageSize 每页显示的数据条数
* @param number $ShowPage 每次显示的页数
*/
public function __construct($CountNum, $PageUrl = NULL, $PageClass = NULL,$CurClass = NULL, $PageSize = 20, $ShowPage = 5) {
$this->ShowPage = $ShowPage;
$this->CountPage = ceil ( $CountNum / $PageSize );
$this->Floorp = floor ( $ShowPage / 2 ); // 偏移量
$this->PageClass = is_null ( $PageClass ) ? '' : $PageClass;
$this->CurClass = is_null ( $CurClass ) ? '' : $CurClass;
// $ServerURL = ( preg_match('/\?/i', $_SERVER['REQUEST_URI']))?preg_replace('/\&p\=[0-9]+/i', "", $_SERVER['REQUEST_URI']) : $_SERVER['REQUEST_URI']."?";
// if( substr($ButURL,0,2)=='//' ){
// $ServerURL = substr($ServerURL,1);
// }
// $url = preg_replace('/p=[\d]*/i', '', $ServerURL);
$url = '';
//推荐自己传url,不传也可以打开上面的代码自动获取
$this->PageUrl = is_null ( $PageUrl ) ? $url : $PageUrl;
}
/**
*
* @param number $Page
* @param string $ShowToPage
* 首页,上下页,尾页
* @param string $Html 标签元素,li,p
* @return string
*/
public function getPage($Page = 1, $ShowToPage = true, $Html = null) {
$StartPage = ($Page - $this->Floorp); // 开始页码
$EndPage = ($Page + $this->Floorp); // 结束页码
if ($this->CountPage ShowPage) {
$StartPage = 1;
$EndPage = $this->CountPage;
}
if ($StartPage ShowPage;
}
if ($EndPage > $this->CountPage) {
$StartPage = $this->CountPage - $this->ShowPage + 1;
$EndPage = $this->CountPage;
}
$PageHtml = '';
if (! is_null ( $Html )) {
if ($Html == 'li') {
$Shtml = '
'; } else { $Shtml = '
'; $Ehtml = '
'; } } if (true == $ShowToPage) { $PageHtml .= "$Shtml« 首页$Ehtml"; $PrveUrl = $this->getPrve($Page); $PageHtml .= "$Shtml« »$Ehtml"; $PageHtml .= "$Shtml尾页 »$Ehtml"; } return $PageHtml; } public function getPrve($Page){ if ($Page != 1) { $Prve = $Page - 1; $PrveUrl = "{$this->PageUrl}p={$Prve}"; } else { $PrveUrl = "{$this->PageUrl}p=1"; } return $PrveUrl; } public function getNext($Page){ if ($Page != $this->CountPage) { $Next = $Page + 1; $NextUrl = "{$this->PageUrl}p={$Next}"; } else { $NextUrl = "{$this->PageUrl}p={$this->CountPage}"; } return $NextUrl; } }
再为大家分享一个主要用于新手学习php分页,代码简单实用,主要是注释很完整。
1. Page.class.php
getPages()); //生成一个页码数组(键为页码,值为链接) * echo $p->showPages(1); //生成一个页码样式(可添加自定义样式) * * @author: Dzer <span><a href="'.%24this->href.'?'.http_build_query(%24_GET).'"></a></span><span><a href="'.%24this->href.'?'.http_build_query(%24_GET).'"></a></span><span><a href="'.%24v.'"></a></span><span><a href="'.%24this->href.'?'.http_build_query(%24_GET).'"></a></span><span><a href="'.%24this->href.'?'.http_build_query(%24_GET).'"></a></span>????358654744>
使用官方Model Context Protocol PHP SDK将PHP应用程序功能暴露为MCP工具、资源和提示,用于代理工作流。
?<pre class="brush:php;toolbar:false;">
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!










