Download the PHP package nabeghe/alphanum without Composer
On this page you can find all versions of the php package nabeghe/alphanum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nabeghe/alphanum
More information about nabeghe/alphanum
Files in nabeghe/alphanum
Package alphanum
Short Description High-performance PHP library for bi-directional conversion between decimal numbers and alphanumeric strings (Base62, Base58, Base60, Base36) with BigInt support.
License MIT
Homepage https://github.com/nabeghe/alphanum-php
Informations about the package alphanum
Alphanum for PHP
A blazing fast, zero-dependency PHP library for converting decimal numbers into alphanumeric formats (Sexagesimal Base-60, Base62, Base58, Base36, and custom alphabets) and vice versa.
Supports PHP 7.4 through PHP 8.5+, BigInt / arbitrary-precision integers, output padding, validation, and instance & static APIs.
๐ Features
- Backwards-Compatible: Seamless drop-in replacement for v0.1 with original sexagesimal encoding preserved.
- High Performance: $O(1)$ cached inverted lookup tables and optimized loop operations (~3M ops/sec).
- Multiple Bases & Custom Alphabets: Built-in support for Sexagesimal (Base 60), Base62, Base58 (Bitcoin style), Base36, or any custom character set.
- BigInt Support: Easily handles numbers exceeding 64-bit
PHP_INT_MAX(e.g. Snowflake IDs, UUIDs, 128-bit numbers) using GMP, BCMath, or a pure-PHP fallback. - Padding & Min Length: Generate fixed-width or padded alphanumeric strings for link shorteners.
- Validation: Fast validation methods to verify format integrity before decoding.
- Flexible API: Clean static methods and configurable Object-Oriented instances.
๐ฆ Installation
Install via Composer:
๐ซก Usage
1. Basic (Default Character Set)
By default, Alphanum uses its standard character set containing digits 0-9, uppercase A-Z, lowercase a-z, and _ (63 characters):
(Note: Alphanum::encode($number) is also available as an alias for Alphanum::generate($number)).
2. Predefined & Custom Alphabets
You can use standard built-in alphabets or provide your own:
3. BigInt / Arbitrary-Precision Numbers
When dealing with IDs that exceed 64-bit integer limits (PHP_INT_MAX), pass the number as a numeric string. The library automatically leverages GMP or BCMath if available, or falls back to an internal pure-PHP arbitrary-precision algorithm:
4. Padding & Minimum Length
Useful for URL shorteners to ensure generated codes have a consistent minimum length:
5. String Validation
Validate whether an input string is composed strictly of characters belonging to the active alphabet and base:
6. Object-Oriented Instance API
Create configured instances to avoid repeating arguments:
๐งช Testing
Run the test suite with PHPUnit:
Tested and verified across PHP 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, and 8.5.
๐ License
Licensed under the MIT license, see LICENSE.md for details.