PHPackages                             dsentker/numeric-range-parser - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. dsentker/numeric-range-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

dsentker/numeric-range-parser
=============================

A parser for reading indexed ranges, e.g. page numbers

0.1.2(2y ago)15DOCPHPPHP &gt;=8.1

Since Mar 12Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dsentker/numeric-range-parser)[ Packagist](https://packagist.org/packages/dsentker/numeric-range-parser)[ RSS](/packages/dsentker-numeric-range-parser/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (4)Used By (0)

NumericRangeParser
==================

[](#numericrangeparser)

A PHP library that provides functionality to parse numeric ranges from a given input string. The library is suitable for user input that wants to select specific page numbers or fetch a custom range of items.

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

[](#installation)

Install using [Composer](https://getcomposer.org/):

```
composer require dsentker/numeric-range-parser
```

Usage
-----

[](#usage)

```
$parser = new DefaultNumericRangeParser();
$result = $parser->parse('1-3;5');
dump($result->toNormalizedArray()); // [1, 2, 3, 5]

// $result is traversable, iterating over indexes is possible too
foreach ($result as $index) {
    echo $index . PHP_EOL;
}
```

As `$result` is an instance of an [AppendIterator](https://www.php.net/manual/en/class.appenditerator.php) it is possible to append more indexes if required. Also, the `getIteratorIndex()` method returns the index of the current block (a block is separated by semicolon)

```
$parser = new DefaultNumericRangeParser();
$result = $parser->parse('4-6; 10'); // two blocks defined here

$result->append(new \ArrayIterator([1-2])); // another block here

foreach ($result as $index) {
    // $result->getIteratorIndex() will count up to 2 (0,1,2)
    printf("Block #%d: Index: #%d", $result->getIteratorIndex(), $result->current());
}
```

Configure options
-----------------

[](#configure-options)

`__construct(string $rangeSeparator = '-', string $blockSeparator = ';')`

The constructor allows you to set custom range and block separators. By default, the range separator is `'-'` and the block separator is `';'`.

```
$instance = new \DSentker\DefaultNumericRangeParser('..', '/');
$result = $instance->parse('1..4 / 6..10');
```

Strict parsing
--------------

[](#strict-parsing)

While the `DefaultNumericRangeParser` is a little more lax on user input, the `StrictNumericRangeParser` parser is stricter. A `RangeException` is thrown if the input is incorrect:

```
$default = new \DSentker\DefaultNumericRangeParser();
$strict = new \DSentker\StrictNumericRangeParser();

$default->parse('10-8'); // No error
$strict->parse('10-8'); // First index is greater than second, RangeException is thrown

$default->parse('8-10;;11'); // No error
$strict->parse('8-10;;11'); // Missing range, RangeException is thrown

$default->parse('8a;10;12'); // No error
$strict->parse('8a;10;12'); // Invalid character, RangeException is thrown
```

Testing
-------

[](#testing)

with PHPUnit:

```
./vendor/bin/phpunit
```

Submitting bugs and feature requests
------------------------------------

[](#submitting-bugs-and-feature-requests)

Bugs and feature request are tracked on GitHub.

If you have general questions or want to implement a feature, you are welcome to collaborate.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

3

Last Release

796d ago

PHP version history (2 changes)0.1.0PHP &gt;=8.2

0.1.2PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/9309c19594a948d4f0314bbdb2d3cfd56c84027fbd0fac6497c3e7098046be63?d=identicon)[dsentker](/maintainers/dsentker)

---

Top Contributors

[![dsentker](https://avatars.githubusercontent.com/u/86192?v=4)](https://github.com/dsentker "dsentker (11 commits)")

---

Tags

parserrangepage-number

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/dsentker-numeric-range-parser/health.svg)

```
[![Health](https://phpackages.com/badges/dsentker-numeric-range-parser/health.svg)](https://phpackages.com/packages/dsentker-numeric-range-parser)
```

###  Alternatives

[nikic/php-parser

A PHP parser written in PHP

17.4k902.6M1.8k](/packages/nikic-php-parser)[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k910.8M118](/packages/doctrine-lexer)[erusev/parsedown

Parser for Markdown.

15.0k151.8M732](/packages/erusev-parsedown)[league/commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)

2.9k404.0M702](/packages/league-commonmark)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)

PHPackages © 2026

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