This is a PHP ULID package
PHP Library to use ULID on your application.
- 128-bit compatibility with UUID
- 1.21e+24 unique ULIDs per millisecond
- Lexicographically sortable!
- Canonically encoded as a 26 character string, as opposed to the 36 character UUID
- Uses Crockford's base32 for better efficiency and readability (5 bits per character)
- Case insensitive
- No special characters (URL safe)
- Monotonic sort order (correctly detects and handles the same millisecond)
You can install the package via composer:
composer require guifelix/php-ulid
use Guifelix\Ulid;
$ulid = Ulid::generate(); // Accept boolean as a parameter for lowercase;
echo (string) $ulid; //0001EH8YAEP8CXP4AMWCHHDBHJ
echo $ulid->getTime(); //0001EH8YAE
echo $ulid->getRandomness(); //P8CXP4AMWCHHDBHJ
echo $ulid->isLowercase(); //false
echo $ulid->toTimestamp(); //1561622862
use Guifelix\Ulid;
$ulid = Ulid::fromTimestamp(1561622862); // Accept boolean as a second parameter for lowercase;
echo (string) $ulid; //0001EH8YAEP8CXP4AMWCHHDBHJ
use Guifelix\Ulid;
$ulid = Ulid::fromString('0001EH8YAEP8CXP4AMWCHHDBHJ'); // Accept boolean as a second parameter for lowercase;
echo (string) $ulid; //0001EH8YAEP8CXP4AMWCHHDBHJ
use Guifelix\Ulid;
Ulid::validate('8ZZZZZZZZZP8CXP4AMWCHHDBHI'); // Case insensitve
/**
* validate Length, Crockford Characters and Time
* Throws
* - InvalidUlidLengthException
* - InvalidUlidCharException
* - InvalidUlidTimestampException <- Max timestamp is 7ZZZZZZZZZ (281474976710655) or until the year 10889 AD :)
* - InvalidUlidException
* /
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
- Robin van der Vleuten - I have used most of his code for this package
- Guilherme Maciel
- All Contributors
The MIT License (MIT). Please see License File for more information.