byjg / shortid
Create short string IDs from numbers
Fund package maintenance!
byjg
Installs: 4 139
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=8.1 <8.4
Requires (Dev)
- phpunit/phpunit: ^9.6
- vimeo/psalm: ^5.9
README
Create short string IDs from numbers
Description
This library enables you to create a very short string from integer numbers.
The basic usage is:
<?php $shortid = \ByJG\Utils\ShortId::fromNumber(81717788171667188198); // Will write: Qi0yuM2uKwJb
Methods
- fromNumber($number, $map = null): Return a short id from a number
- fromHex($hex, $map = null): Return a short id from a Hex value
- fromUuid($uuid, $map = null): Return a short id from a UUID
- fromRandom($min, $max, $map = null): Return a short id from a random number
- get($shortid, $map = null): Return the Unique Integer Number from the short id (does not work with UUIDs)
Specify your own map
The base of the short id is in the map definition.
Basically, you can create your own sequence here.
The library defines four by default:
- $MAP_DEFAULT
- $MAP_ALTERNATE
- $MAP_NUMBERS_FIRST
- $MAP_RANDOM
The basic usage is:
<?php $shortid = \ByJG\Utils\ShortId::fromNumber( 81717788171667188198, \ByJG\Utils\ShortId::$MAP_NUMBERS_FIRST ); // Will write: G8QokCSkAmz1
Installation
composer require "byjg/php-shortid"
Tests
vendor/bin/phpunit