Hướng dẫn shortid php
Show This library is an implementation of ShortId for PHP. Basic usageJust call use PUGX\Shortid\Shortid; require_once __DIR__.'/vendor/autoload.php'; $id = Shortid::generate(); Advanced usageIn the following example, you can see how to change the basic alphabet and default length. Default alphabet uses all letters (lowercase and uppercase), all numbers, underscore, and hypen. use PUGX\Shortid\Factory; use PUGX\Shortid\Shortid; require_once __DIR__.'/vendor/autoload.php'; $factory = new Factory(); // alphabet string must be 64 characters long $factory->setAlphabet('é123456789àbcdefghìjklmnòpqrstùvwxyzABCDEFGHIJKLMNOPQRSTUVWX.!@|'); // length must be between 2 and 20 (default is 7) // of course, a lower length is increasing clashing probability $factory->setLength(9); Shortid::setFactory($factory); $id = Shortid::generate(); As alternative, you can customize single generations: use PUGX\Shortid\Shortid; require_once __DIR__.'/vendor/autoload.php'; $id9 = Shortid::generate(9, 'é123456789àbcdefghìjklmnòpqrstùvwxyzABCDEFGHIJKLMNOPQRSTUVWX.!@|'); $id5 = Shortid::generate(5); More readable stringsSometimes, you want to avoid some ambiguous characters, like Example: use PUGX\Shortid\Shortid; require_once __DIR__.'/vendor/autoload.php'; $id = Shortid::generate(7, null, true); Pre-defined valuesIf 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. use PUGX\Shortid\Shortid; require_once __DIR__.'/vendor/autoload.php'; $myFixedId = new Shortid('5h0r71d'); $anotherFixedId = new Shortid('fooBarZ'); DoctrineIf you want to use ShortId with Doctrine ORM, take a look to ShortId Doctrine type. Doctrine and SymfonyIf you want to use ShortId with Doctrine ORM and Symfony framework, take a look to ShortId Doctrine type bundle. mbstring extensionThis library uses a polyfill, so it can used in environments where mbstring native extension is not available. If, instead, your environment is offering such extension, you can avoid installing polyfill by configuring replace entry in your |