Download the PHP package pugx/shortid-php without Composer
On this page you can find all versions of the php package pugx/shortid-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pugx/shortid-php
More information about pugx/shortid-php
Files in pugx/shortid-php
Package shortid-php
Short Description An implementation of shortid in PHP
License MIT
Homepage http://pugx.org/
Informations about the package shortid-php
ShortId
This library is an implementation of ShortId for PHP.
Installation
Install the library via Composer:
Usage
ShortId is a PHP library that generates short, unique, and random strings. It's useful in scenarios where you need concise identifiers, such as URL shortening or generating unique keys.
Basic usage
Just call PUGX\Shortid\Shortid::generate()
to get a random string with default length 7, like "MfiYIvI".
Advanced usage
For more control, you can customize the alphabet and length using the Factory class.
The default alphabet uses all letters (lowercase and uppercase), all numbers, underscore, and hyphen.
As an alternative, you can customize single generations:
More readable strings
Sometimes, you want to avoid some ambiguous characters, like B
/8
or I
/l
(uppercase/lowercase).
In this case, you can pass a third parameter true
to the generate
method. Notice that in this case the alphabet
will be ignored, so it makes sense to pass a null one.
Example:
Pre-defined values
If you need a deterministic string, instead of a random one, you can call directly the class constructor. This could be useful, for instance, when you need pre-defined data for testing purposes.
Doctrine
If you want to use ShortId with Doctrine ORM, take a look at ShortId Doctrine type.
Doctrine and Symfony
If you want to use ShortId with Doctrine ORM and Symfony framework, take a look to ShortId Doctrine type bundle.
Dependencies replacement
This library uses a polyfill, so it can be used in environments where the mbstring native extension is not available.
If, instead, your environment is offering that extension, you can avoid installing
that polyfill by configuring a replace entry in your composer.json
.
The same applies to the randomLib library: if you are using PHP 8.3 or higher,
you can replace it, since this library uses the native Random
class instead.
Contributing
Contributions are welcome. Feel free to open a Pull Request or file an issue here on GitHub! Please read the contributing guidelines first.