我正在使用php分页功能
功能是
/**
* Displays pagination links based on given parameters
*
* @param int $currentPage - current page
* @param int $itemCount - number of items to paginate, used to calculate total number of pages
* @param int $itemsPerPage - number of items per page, used to calculate total number of pages
* @param int $adjacentCount - half the number of page links displayed adjacent to the current page
* @param (string|callable) $pageLinkTemplate - pagination URL string containing %d placeholder or a callable function that accepts page number and returns page URL
* @param boolean $showPrevNext - whether to show previous and next page links
* @return void
*/
function pagination($currentPage, $itemCount, $itemsPerPage, $adjacentCount, $pageLinkTemplate, $showPrevNext = true) {
$firstPage = 1;
$lastPage = ceil($itemCount / $itemsPerPage);
if ($lastPage == 1) {
return;
}
if ($currentPage <= $adjacentCount - $adjacentCount) {
$firstAdjacentPage = $firstPage;
$lastAdjacentPage = min($firstPage + $adjacentCount + $adjacentCount, $lastPage);
} elseif ($currentPage > $lastPage - $adjacentCount - $adjacentCount) {
$lastAdjacentPage = $lastPage;
$firstAdjacentPage = $lastPage - $adjacentCount - $adjacentCount;
} else {
$firstAdjacentPage = $currentPage - $adjacentCount;
$lastAdjacentPage = $currentPage + $adjacentCount;
}
echo '<div>';
if ($showPrevNext) {
if ($currentPage == $firstPage - 1) {
echo '<li><span class="1 searchPaginationPrev list-first"><</span></li>';
} else {
echo '<li><a class="2 searchPaginationPrev list-first" href="' . (is_callable($pageLinkTemplate) ? $pageLinkTemplate($currentPage - 1) : sprintf($pageLinkTemplate, $currentPage - 1)) . '"><</a></li>';
}
}
if ($firstAdjacentPage > $firstPage) {
echo '<li><a class="3 searchPaginationNonSelected" href="' . (is_callable($pageLinkTemplate) ? $pageLinkTemplate($firstPage) : sprintf($pageLinkTemplate, $firstPage)) . '">' . $firstPage . '</a></li>';
if ($firstAdjacentPage > $firstPage + 1) {
echo '<li><span class="1">...</span></li>';
}
}
for ($i = $firstAdjacentPage; $i <= $lastAdjacentPage; $i++) {
if ($currentPage == $i - 1) {
echo '<li><span class="4 searchPaginationSelected">' . $i . '</span></li>';
} else {
echo '<li><a class="5 searchPaginationNonSelected" href="'. (is_callable($pageLinkTemplate) ? $pageLinkTemplate($i - 1) : sprintf($pageLinkTemplate, $i - 1)).'">' . $i . '</a></li>';
}
}
if ($lastAdjacentPage < $lastPage) {
if ($lastAdjacentPage < $lastPage - 1) {
echo '<li><span class="2">...</span></li>';
}
echo '<li><a class="6 searchPaginationNonSelected" href="' . (is_callable($pageLinkTemplate) ? $pageLinkTemplate($lastPage) : sprintf($pageLinkTemplate, $lastPage - 1)) . '">' . $lastPage . '</a></li>';
}
if ($showPrevNext) {
if ($currentPage == $lastPage) {
echo '<li><span class="7 searchPaginationNext list-last">></span></li>';
} else {
echo '<li><a class="8 searchPaginationNext list-last" href="' . (is_callable($pageLinkTemplate) ? $pageLinkTemplate($currentPage + 1) : sprintf($pageLinkTemplate, $currentPage + 1)) . '">></a></li>';
}
}
echo '</div>';
}
我回应了像
这样的功能pagination(Params::getParam('iPage'), $iTotalItems, $itemsPerPage, 2, osc_update_search_url(array('iPage'=>%d)));
它运作良好,但我在网址上有一些空格..如何删除空间..我也尝试使用str_replace,preg_replace但没有用..任何人都可以帮助我...
我得到的函数here