PHP code example of phossa2 / uuid

1. Go to this page and download the library: Download phossa2/uuid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phossa2 / uuid example snippets


use Phossa2\Uuid\Uuid;

// 2100020bc58eb7f18602000100010000
$uuid = Uuid::get();

// encode/shorten it, can be used in URL
if (Uuid::isValid($uuid)) {
    // AWprUw7urpN8bbQ4LciGNa
    $short = Uuid::encode($uuid);

    // decode
    var_dump($uuid === Uuid::decode($short)); // true
}

class MyUuid extends Uuid
{
    /*
     * use this vendor id
     *
     * {@inheritDoc}
     */
    protected $vendor = '1234';

    /*
     * use this more reliable sequence
     *
     * {@inheritDoc}
     */
    protected function getSequence()
    {
         // ...
    }
}