PHPackages                             rancoud/pagination - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. rancoud/pagination

ActiveLibrary[Testing &amp; Quality](/categories/testing)

rancoud/pagination
==================

Pagination package

4.0.2(1mo ago)39.8k—0%1MITPHPPHP &gt;=8.4.0CI passing

Since Jan 20Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/rancoud/Pagination)[ Packagist](https://packagist.org/packages/rancoud/pagination)[ RSS](/packages/rancoud-pagination/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (32)Used By (0)

Pagination Package
==================

[](#pagination-package)

[![Packagist PHP Version Support](https://camo.githubusercontent.com/ff5cc9fac85e2a8bea273d262621e0e5947bd1c347fd0a5c07a1d12ad15d9025/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72616e636f75642f706167696e6174696f6e)](https://camo.githubusercontent.com/ff5cc9fac85e2a8bea273d262621e0e5947bd1c347fd0a5c07a1d12ad15d9025/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72616e636f75642f706167696e6174696f6e)[![Packagist Version](https://camo.githubusercontent.com/5b7e7ce6efcb76c09f48ca7af6f84b80343b4f503f58d6cff738bd78bd6f2057/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616e636f75642f706167696e6174696f6e)](https://packagist.org/packages/rancoud/pagination)[![Packagist Downloads](https://camo.githubusercontent.com/cf660a91d46c603bcf842b87c5cb0e0651ad8b7cf67515fb30ef3cbf2bdef7b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72616e636f75642f706167696e6174696f6e)](https://packagist.org/packages/rancoud/pagination)[![Composer dependencies](https://camo.githubusercontent.com/e176e220268ba29b476d8db8874191c7519478a64fd9992bf9973015edcffcce/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d312d627269676874677265656e)](https://github.com/rancoud/Pagination/blob/master/composer.json)[![Test workflow](https://camo.githubusercontent.com/b2e10dd4f3f07c12029938de32d49e0766324e965f4de17b63a7b31755a69773/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72616e636f75642f706167696e6174696f6e2f746573742e796d6c3f6272616e63683d6d6173746572)](https://github.com/rancoud/pagination/actions/workflows/test.yml)[![Codecov](https://camo.githubusercontent.com/bb4b1d59a9edeb094b7b736f122844e6480ff797be05478dd6d93946cd22f496/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f72616e636f75642f706167696e6174696f6e3f6c6f676f3d636f6465636f76)](https://codecov.io/gh/rancoud/pagination)

Generate HTML pagination for accessibility.

Dependencies
------------

[](#dependencies)

Security package:

Installation
------------

[](#installation)

```
composer require rancoud/pagination
```

How to use it?
--------------

[](#how-to-use-it)

```
use Rancoud\Pagination\Pagination;

$currentPage = 1;
$countElements = 10;
$countElementPerPage = 5;

$p = new Pagination();
$html = $p->generateHtml($currentPage, $countElements, $countElementPerPage);
echo $html;
```

It will output

```

            1

            2

```

Lexicon
-------

[](#lexicon)

- **Root** represents ``
- **Item** represents ``
- **Link** represents ``

Pagination Constructor
----------------------

[](#pagination-constructor)

### Settings

[](#settings)

#### Optionnals

[](#optionnals)

ParameterTypeDefault valueDescriptionconfigurationarray\[\]Parameters for changing pagination behaviorPagination Methods
------------------

[](#pagination-methods)

### General Commands

[](#general-commands)

Generates HTML pagination.

```
public function generateHtml(int $currentPage, int $countElements, int $countElementPerPage): string
```

Generates pagination and returns as array.

```
public function generateData(int $currentPage, int $countElements, int $countElementPerPage): array
```

For changing pagination behavior.
Checks for each valid props:

- when using string: force string type
- when using tag: use regex `/^[a-zA-Z-]+$/i` otherwise ignored
- when using bool: force bool type
- when using int: force int type and check if value is equal or greater than 0, otherwise use 0.

```
public function setConfiguration(array $configuration): void
```

### Static methods

[](#static-methods)

Computes number of pages.
The formula is `ceil($countElements / $countElementPerPage)`.

```
public static function countPages(int $countElements, int $countElementPerPage): int
```

Finds the page where the item index is located.
The formula is `ceil($itemIndex / $countElementPerPage)`.

```
public static function locateItemInPage(int $countElementPerPage, int $itemIndex): int
```

Configuration Parameters
------------------------

[](#configuration-parameters)

### Url

[](#url)

- url (string) ([example](#url-1))

### Behavior

[](#behavior)

- show\_all\_links (bool: false) ([example](#show_all_links))
- use\_previous (bool: false) ([example](#use_previous))
- always\_use\_previous (bool: false) ([example](#always_use_previous))
- use\_next (bool: false) ([example](#use_next))
- always\_use\_next (bool: false) ([example](#always_use_next))
- use\_dots (bool: false) ([example](#use_dots))
- count\_pages\_pair\_limit (int: 0) ([example](#count_pages_pair_limit))
- count\_pages\_pair\_adjacent (int: 2) ([example](#count_pages_pair_adjacent))

### Labels

[](#labels)

- text\_previous (string: Previous page) ([example](#text_previous))
- text\_next (string: Next page) ([example](#text_next))
- text\_dots (string: …) ([example](#text_dots))
- text\_page (string: {{PAGE}}) ([example](#text_page))
- aria\_label\_link (string: Goto page {{PAGE}}) ([example](#aria_label_link))
- aria\_label\_current\_link (string: Current page, page {{PAGE}}) ([example](#aria_label_current_link))
- aria\_label\_nav (string: Pagination) ([example](#aria_label_nav))
- aria\_label\_previous (string: Previous page) ([example](#aria_label_previous))
- aria\_label\_next (string: Next page) ([example](#aria_label_next))
- thousands\_separator (string) ([example](#thousands_separator))

### HTML markup

[](#html-markup)

#### Root

[](#root)

- root\_tag (string: ul) ([example](#root_tag))
- root\_attrs (string) ([example](#root_attrs))
- use\_nav (bool: true) ([example](#use_nav))
- nav\_attrs (string) ([example](#nav_attrs))

#### Item

[](#item)

- item\_tag (string: li) ([example](#item_tag))
- item\_attrs (string) ([example](#item_attrs))
- item\_attrs\_current (string) ([example](#item_attrs_current))
- item\_previous\_attrs (string) ([example](#item_previous_attrs))
- item\_previous\_attrs\_disabled (string) ([example](#item_previous_attrs_disabled))
- item\_next\_attrs (string) ([example](#item_next_attrs))
- item\_next\_attrs\_disabled (string) ([example](#item_next_attrs_disabled))
- item\_dots\_attrs (string) ([example](#item_dots_attrs))

#### Link

[](#link)

- link\_tag (string: a) ([example](#link_tag))
- link\_attrs (string) ([example](#link_attrs))
- link\_attrs\_current (string) ([example](#link_attrs_current))
- link\_previous\_attrs\_disabled (string) ([example](#link_previous_attrs_disabled))
- link\_next\_attrs\_disabled (string) ([example](#link_next_attrs_disabled))
- dot\_tag (string: span) ([example](#dot_tag))
- dot\_attrs (string) ([example](#dot_attrs))

#### Indentation

[](#indentation)

- use\_pretty\_html (bool: true) ([example](#use_pretty_html))
- html\_tab\_sequence (string: \\t) ([example](#html_tab_sequence))
- html\_initial\_indentation (int: 0) ([example](#html_initial_indentation))

#### Security

[](#security)

- esc\_attr (bool: true) ([example](#esc_attr))
- esc\_html (bool: true) ([example](#esc_html))
- charset (string: UTF-8) ([example](#charset))

You have to sanitize by yourself thoses parameters:

- nav\_attrs
- root\_attrs
- item\_attrs
- item\_attrs\_current
- item\_previous\_attrs
- item\_previous\_attrs\_disabled
- item\_next\_attrs
- item\_next\_attrs\_disabled
- item\_dots\_attrs
- link\_attrs
- link\_attrs\_current
- link\_previous\_attrs\_disabled
- link\_next\_attrs\_disabled
- dot\_attrs
- html\_tab\_sequence

Examples
--------

[](#examples)

### url

[](#url-1)

Page append at the end

#### Input

[](#input)

```
$conf = [
    'url' => 'https://example.com/news/page/'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output)

```

            1

            2

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-1)

```
$conf = [
    'url' => 'https://example.com/news/page/{{PAGE}}/?date=desc'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-1)

```

            1

            2

```

After page replace with {{PAGE}} pattern

#### Input

[](#input-2)

```
$conf = [
    'url' => '{{PAGE}}?date=desc'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-2)

```

            1

            2

```

[⏫ Configuration Parameters / Url](#url)

### show\_all\_links

[](#show_all_links)

#### Input

[](#input-3)

```
$conf = [
    'show_all_links' => true
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);
```

#### Output

[](#output-3)

```

            1

            2

            3

            4

            5

            6

```

[⏫ Configuration Parameters / Behavior](#behavior)

### use\_previous

[](#use_previous)

#### Input

[](#input-4)

```
$conf = [
    'use_previous' => true
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);
```

#### Output

[](#output-4)

```

            Previous page

            1

            2

```

[⏫ Configuration Parameters / Behavior](#behavior)

### always\_use\_previous

[](#always_use_previous)

Previous has `aria-disabled=true` on link tag if there is no previous page

#### Input

[](#input-5)

```
$conf = [
    'always_use_previous' => true
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-5)

```

            Previous page

            1

            2

```

[⏫ Configuration Parameters / Behavior](#behavior)

### use\_next

[](#use_next)

#### Input

[](#input-6)

```
$conf = [
    'use_next' => true
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-6)

```

            1

            2

            Next page

```

[⏫ Configuration Parameters / Behavior](#behavior)

### always\_use\_next

[](#always_use_next)

Next has `aria-disabled=true` on link tag if there is no next page

#### Input

[](#input-7)

```
$conf = [
    'always_use_next' => true
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);
```

#### Output

[](#output-7)

```

            1

            2

            Next page

```

[⏫ Configuration Parameters / Behavior](#behavior)

### use\_dots

[](#use_dots)

#### Input

[](#input-8)

```
$conf = [
    'use_dots' => true
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);
```

#### Output

[](#output-8)

```

            1

            2

            3

            …

```

[⏫ Configuration Parameters / Behavior](#behavior)

### count\_pages\_pair\_limit

[](#count_pages_pair_limit)

#### Input

[](#input-9)

```
$conf = [
    'count_pages_pair_limit' => 1
];
echo (new Pagination($conf))->generateHtml(5, 300, 5);
```

#### Output

[](#output-9)

```

            1

            3

            4

            5

            6

            7

            60

```

[⏫ Configuration Parameters / Behavior](#behavior)

### count\_pages\_pair\_adjacent

[](#count_pages_pair_adjacent)

#### Input

[](#input-10)

```
$conf = [
    'count_pages_pair_adjacent' => 1
];
echo (new Pagination($conf))->generateHtml(5, 300, 5);
```

#### Output

[](#output-10)

```

            4

            5

            6

```

[⏫ Configuration Parameters / Behavior](#behavior)

### count\_pages\_pair\_adjacent + count\_pages\_pair\_adjacent

[](#count_pages_pair_adjacent--count_pages_pair_adjacent)

count\_pages\_pair\_limit 0 + count\_pages\_pair\_adjacent 0

#### Input

[](#input-11)

```
$conf = [
    'count_pages_pair_limit' => 0,
    'count_pages_pair_adjacent' => 0
];
echo (new Pagination($conf))->generateHtml(5, 300, 5);
```

#### Output

[](#output-11)

```

            5

```

count\_pages\_pair\_limit 2 + count\_pages\_pair\_adjacent 2

#### Input

[](#input-12)

```
$conf = [
    'count_pages_pair_limit' => 2,
    'count_pages_pair_adjacent' => 2
];
echo (new Pagination($conf))->generateHtml(5, 300, 5);
```

#### Output

[](#output-12)

```

            1

            2

            3

            4

            5

            6

            7

            59

            60

```

[⏫ Configuration Parameters / Behavior](#behavior)

### text\_previous

[](#text_previous)

#### Input

[](#input-13)

```
$conf = [
    'use_previous' => true,
    'text_previous' => 'prev'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);
```

#### Output

[](#output-13)

```

            prev

            1

            2

```

[⏫ Configuration Parameters / Labels](#labels)

### text\_next

[](#text_next)

#### Input

[](#input-14)

```
$conf = [
    'use_next' => true,
    'text_next' => 'next'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-14)

```

            1

            2

            next

```

[⏫ Configuration Parameters / Labels](#labels)

### text\_dots

[](#text_dots)

#### Input

[](#input-15)

```
$conf = [
    'use_dots' => true,
    'text_dots' => 'dots'
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);
```

#### Output

[](#output-15)

```

            1

            2

            3

            dots

```

[⏫ Configuration Parameters / Labels](#labels)

### text\_page

[](#text_page)

Page append at the end

#### Input

[](#input-16)

```
$conf = [
    'text_page' => 'yolo'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-16)

```

            yolo 1

            yolo 2

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-17)

```
$conf = [
    'text_page' => 'yo {{PAGE}} lo'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-17)

```

            yo 1 lo

            yo 2 lo

```

[⏫ Configuration Parameters / Labels](#labels)

### aria\_label\_link

[](#aria_label_link)

#### Input

[](#input-18)

```
$conf = [
    'aria_label_link' => 'aria label link'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-18)

```

            1

            2

```

With {{PAGE}} pattern

#### Input

[](#input-19)

```
$conf = [
    'aria_label_link' => 'aria label link {{PAGE}}'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-19)

```

            1

            2

```

[⏫ Configuration Parameters / Labels](#labels)

### aria\_label\_current\_link

[](#aria_label_current_link)

#### Input

[](#input-20)

```
$conf = [
    'aria_label_current_link' => 'aria label current link'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-20)

```

            1

            2

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-21)

```
$conf = [
    'aria_label_current_link' => 'aria label current link {{PAGE}}'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-21)

```

            1

            2

```

[⏫ Configuration Parameters / Labels](#labels)

### aria\_label\_nav

[](#aria_label_nav)

#### Input

[](#input-22)

```
$conf = [
    'aria_label_nav' => 'aria label nav'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-22)

```

            1

            2

```

[⏫ Configuration Parameters / Labels](#labels)

### aria\_label\_previous

[](#aria_label_previous)

#### Input

[](#input-23)

```
$conf = [
    'use_previous' => true,
    'aria_label_previous' => 'prev'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);
```

#### Output

[](#output-23)

```

            Previous page

            1

            2

```

[⏫ Configuration Parameters / Labels](#labels)

### aria\_label\_next

[](#aria_label_next)

#### Input

[](#input-24)

```
$conf = [
    'use_next' => true,
    'aria_label_next' => 'next'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-24)

```

            1

            2

            Next page

```

[⏫ Configuration Parameters / Labels](#labels)

### thousands\_separator

[](#thousands_separator)

#### Input

[](#input-25)

```
$conf = [
    'thousands_separator' => ';',
    'count_pages_pair_limit' => 1
];
echo (new Pagination($conf))->generateHtml(1, 1000, 1);
```

#### Output

[](#output-25)

```

            1

            2

            3

            1;000

```

[⏫ Configuration Parameters / Labels](#labels)

### root\_tag

[](#root_tag)

#### Input

[](#input-26)

```
$conf = [
    'root_tag' => 'root'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-26)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Root](#root)

### root\_attrs

[](#root_attrs)

#### Input

[](#input-27)

```
$conf = [
    'root_attrs' => 'data-root="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-27)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Root](#root)

### use\_nav

[](#use_nav)

#### Input

[](#input-28)

```
$conf = [
    'use_nav' => false
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-28)

```

        1

        2

```

[⏫ Configuration Parameters / HTML markup / Root](#root)

### nav\_attrs

[](#nav_attrs)

#### Input

[](#input-29)

```
$conf = [
    'nav_attrs' => 'data-item="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-29)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Root](#root)

### item\_tag

[](#item_tag)

#### Input

[](#input-30)

```
$conf = [
    'item_tag' => 'item'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-30)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Item](#item)

### item\_attrs

[](#item_attrs)

#### Input

[](#input-31)

```
$conf = [
    'item_attrs' => 'data-item="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-31)

```

            1

            2

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-32)

```
$conf = [
    'item_attrs' => 'data-item="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-32)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Item](#item)

### item\_attrs\_current

[](#item_attrs_current)

#### Input

[](#input-33)

```
$conf = [
    'item_attrs_current' => 'data-item-current="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-33)

```

            1

            2

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-34)

```
$conf = [
    'item_attrs_current' => 'data-item-current="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-34)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Item](#item)

### item\_previous\_attrs

[](#item_previous_attrs)

#### Input

[](#input-35)

```
$conf = [
    'use_previous' => true,
    'item_previous_attrs' => 'data-item-previous="attrs"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);
```

#### Output

[](#output-35)

```

            Previous page

            1

            2

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-36)

```
$conf = [
    'use_previous' => true,
    'item_previous_attrs' => 'data-item-previous="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);
```

#### Output

[](#output-36)

```

            Previous page

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Item](#item)

### item\_previous\_attrs\_disabled

[](#item_previous_attrs_disabled)

#### Input

[](#input-37)

```
$conf = [
    'always_use_previous' => true,
    'item_previous_attrs_disabled' => 'data-item-previous-disabled="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-37)

```

            Previous page

            1

            2

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-38)

```
$conf = [
    'always_use_previous' => true,
    'item_previous_attrs_disabled' => 'data-item-previous-disabled="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-38)

```

            Previous page

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Item](#item)

### item\_next\_attrs

[](#item_next_attrs)

#### Input

[](#input-39)

```
$conf = [
    'use_next' => true,
    'item_next_attrs' => 'data-item-next="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-39)

```

            1

            2

            Next page

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-40)

```
$conf = [
    'use_next' => true,
    'item_next_attrs' => 'data-item-next="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-40)

```

            1

            2

            Next page

```

[⏫ Configuration Parameters / HTML markup / Item](#item)

### item\_next\_attrs\_disabled

[](#item_next_attrs_disabled)

#### Input

[](#input-41)

```
$conf = [
    'always_use_next' => true,
    'item_next_attrs_disabled' => 'data-item-next-disabled="attrs"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);
```

#### Output

[](#output-41)

```

            1

            2

            Next page

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-42)

```
$conf = [
    'always_use_next' => true,
    'item_next_attrs_disabled' => 'data-item-next-disabled="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);
```

#### Output

[](#output-42)

```

            1

            2

            Next page

```

[⏫ Configuration Parameters / HTML markup / Item](#item)

### item\_dots\_attrs

[](#item_dots_attrs)

#### Input

[](#input-43)

```
$conf = [
    'use_dots' => true,
    'item_dots_attrs' => 'data-item-dots="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);
```

#### Output

[](#output-43)

```

            1

            2

            3

            …

```

[⏫ Configuration Parameters / HTML markup / Item](#item)

### link\_tag

[](#link_tag)

#### Input

[](#input-44)

```
$conf = [
    'link_tag' => 'link'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-44)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Link](#link)

### link\_attrs

[](#link_attrs)

#### Input

[](#input-45)

```
$conf = [
    'link_attrs' => 'data-link="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-45)

```

            1

            2

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-46)

```
$conf = [
    'link_attrs' => 'data-link="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-46)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Link](#link)

### link\_attrs\_current

[](#link_attrs_current)

#### Input

[](#input-47)

```
$conf = [
    'link_attrs_current' => 'data-link-current="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-47)

```

            1

            2

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-48)

```
$conf = [
    'link_attrs_current' => 'data-link-current="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-48)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Link](#link)

### link\_previous\_attrs\_disabled

[](#link_previous_attrs_disabled)

#### Input

[](#input-49)

```
$conf = [
    'always_use_previous' => true,
    'link_previous_attrs_disabled' => 'data-item-next-disabled="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-49)

```

            Previous page

            1

            2

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-50)

```
$conf = [
    'always_use_previous' => true,
    'link_previous_attrs_disabled' => 'data-item-next-disabled="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-50)

```

            Previous page

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Link](#link)

### link\_next\_attrs\_disabled

[](#link_next_attrs_disabled)

#### Input

[](#input-51)

```
$conf = [
    'always_use_next' => true,
    'link_next_attrs_disabled' => 'data-item-next-disabled="attrs"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);
```

#### Output

[](#output-51)

```

            1

            2

            Next page

```

Page replace with {{PAGE}} pattern

#### Input

[](#input-52)

```
$conf = [
    'always_use_next' => true,
    'link_next_attrs_disabled' => 'data-item-next-disabled="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);
```

#### Output

[](#output-52)

```

            1

            2

            Next page

```

[⏫ Configuration Parameters / HTML markup / Link](#link)

### dot\_tag

[](#dot_tag)

#### Input

[](#input-53)

```
$conf = [
    'use_dots' => true,
    'dot_tag' => 'p'
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);
```

#### Output

[](#output-53)

```

            1

            2

            3

            …

```

[⏫ Configuration Parameters / HTML markup / Link](#link)

### dot\_attrs

[](#dot_attrs)

#### Input

[](#input-54)

```
$conf = [
    'use_dots' => true,
    'dot_attrs' => 'data-dot="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);
```

#### Output

[](#output-54)

```

            1

            2

            3

            …

```

[⏫ Configuration Parameters / HTML markup / Link](#link)

### use\_pretty\_html

[](#use_pretty_html)

#### Input

[](#input-55)

```
$conf = [
    'use_pretty_html' => false
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-55)

```
12
```

[⏫ Configuration Parameters / HTML markup / Indentation](#indentation)

### html\_tab\_sequence

[](#html_tab_sequence)

#### Input

[](#input-56)

```
$conf = [
    'html_tab_sequence' => ''
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-56)

```

1

2

```

[⏫ Configuration Parameters / HTML markup / Indentation](#indentation)

### html\_initial\_indentation

[](#html_initial_indentation)

#### Input

[](#input-57)

```
$conf = [
    'html_initial_indentation' => 1
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-57)

```

                1

                2

```

[⏫ Configuration Parameters / HTML markup / Indentation](#indentation)

### esc\_attr

[](#esc_attr)

#### Input

[](#input-58)

```
$conf = [
    'esc_attr' => false
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-58)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Security](#security)

### esc\_html

[](#esc_html)

#### Input

[](#input-59)

```
$conf = [
    'esc_html' => false,
    'text_page' => '{{PAGE}}'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-59)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Security](#security)

### charset

[](#charset)

#### Input

[](#input-60)

```
$conf = [
    'charset' => 'EUC-JP'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);
```

#### Output

[](#output-60)

```

            1

            2

```

[⏫ Configuration Parameters / HTML markup / Security](#security)

generateData output
-------------------

[](#generatedata-output)

```
$conf = [
    'always_use_previous' => true,
    'always_use_next' => true,
    'use_dots' => true,
]
var_dump(new Pagination($conf))->generateData(1, 3000, 5);

array (size=3)
  'previous' =>
    object(Rancoud\Pagination\Item)[2]
      public 'ariaLabel' => string 'Previous&#x20;page' (length=18)
      public 'href' => string '&#x23;' (length=6)
      public 'itemAttrs' => string '' (length=0)
      public 'linkAttrs' => string '' (length=0)
      public 'text' => string 'Previous page' (length=13)
      public 'isCurrent' => boolean false
      public 'isDots' => boolean false
      public 'isDisabled' => boolean true
      public 'page' => int 0
  'links' =>
    array (size=4)
      0 =>
        object(Rancoud\Pagination\Item)[4]
          public 'ariaLabel' => string 'Page&#x20;1' (length=11)
          public 'href' => string '&#x23;' (length=6)
          public 'itemAttrs' => string '' (length=0)
          public 'linkAttrs' => string '' (length=0)
          public 'text' => string '1' (length=1)
          public 'isCurrent' => boolean true
          public 'isDots' => boolean false
          public 'isDisabled' => boolean false
          public 'page' => int 1
      1 =>
        object(Rancoud\Pagination\Item)[5]
          public 'ariaLabel' => string 'Page&#x20;2' (length=11)
          public 'href' => string '2' (length=1)
          public 'itemAttrs' => string '' (length=0)
          public 'linkAttrs' => string '' (length=0)
          public 'text' => string '2' (length=1)
          public 'isCurrent' => boolean false
          public 'isDots' => boolean false
          public 'isDisabled' => boolean false
          public 'page' => int 2
      2 =>
        object(Rancoud\Pagination\Item)[6]
          public 'ariaLabel' => string 'Page&#x20;3' (length=11)
          public 'href' => string '3' (length=1)
          public 'itemAttrs' => string '' (length=0)
          public 'linkAttrs' => string '' (length=0)
          public 'text' => string '3' (length=1)
          public 'isCurrent' => boolean false
          public 'isDots' => boolean false
          public 'isDisabled' => boolean false
          public 'page' => int 3
      3 =>
        object(Rancoud\Pagination\Item)[7]
          public 'ariaLabel' => string 'Page&#x20;4' (length=11)
          public 'href' => string '4' (length=1)
          public 'itemAttrs' => string '' (length=0)
          public 'linkAttrs' => string '' (length=0)
          public 'text' => string '…' (length=3)
          public 'isCurrent' => boolean false
          public 'isDots' => boolean true
          public 'isDisabled' => boolean false
          public 'page' => int 4
  'next' =>
    object(Rancoud\Pagination\Item)[8]
      public 'ariaLabel' => string 'Next&#x20;page' (length=14)
      public 'href' => string '2' (length=1)
      public 'itemAttrs' => string '' (length=0)
      public 'linkAttrs' => string '' (length=0)
      public 'text' => string 'Next page' (length=9)
      public 'isCurrent' => boolean false
      public 'isDots' => boolean false
      public 'isDisabled' => boolean false
      public 'page' => int 2
```

How to Dev
----------

[](#how-to-dev)

`composer ci` for php-cs-fixer and phpunit and coverage
`composer lint` for php-cs-fixer
`composer test` for phpunit and coverage

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance90

Actively maintained with recent releases

Popularity29

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 76.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~93 days

Recently: every ~119 days

Total

29

Last Release

51d ago

Major Versions

1.0.2 → 2.0.02020-05-14

2.1.1 → 3.0.02020-09-04

3.2.2 → 4.0.02025-04-20

PHP version history (3 changes)1.0.0PHP &gt;=7.2.0

2.0.0PHP &gt;=7.4.0

4.0.0PHP &gt;=8.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/829a536bd4f71cadcd0266e272ccaf413e3fc9f2937248c9a2317ef0bf2d25ee?d=identicon)[rancoud](/maintainers/rancoud)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (243 commits)")[![rancoud](https://avatars.githubusercontent.com/u/1884186?v=4)](https://github.com/rancoud "rancoud (76 commits)")

---

Tags

a11yariaaria-labelcomposercoveragehtmlpackagistpaginationphpphp7php8phpunit

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/rancoud-pagination/health.svg)

```
[![Health](https://phpackages.com/badges/rancoud-pagination/health.svg)](https://phpackages.com/packages/rancoud-pagination)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
