PHP code example of mediagone / small-uid

1. Go to this page and download the library: Download mediagone/small-uid 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/ */

    

mediagone / small-uid example snippets


$uid = SmallUid::random();

$uid = SmallUid::fromHex('1234567890abcdef');

$uid = SmallUid::fromString('LscmjzUyKLR');

$uid = SmallUid::nil();

$uid = SmallUid::fromHex('1234567890abcdef');
(string)$uid; // string(11) "LscmjzUyKLR"

$uid = SmallUid::fromString('LscmjzUyKLR');

$uid = SmallUid::fromString('LscmjzUyKLR');
(string)$uid->getHex(); // string(16) "1234567890abcdef"

$uid = SmallUid::fromString('LscmjzUyKLR');

(string)$uid->toHex()->toDecimal(); // int(1311768467294899695)
(string)$uid->toHex()->toHex()->toBinary(); // string(8) "4Vx" (binary string)

$uid = SmallUid::fromHex('1234567890abcdef');

$datetime = $uid->getCreationDatetime(); // retrieve Uid's creation datetime
(string)$creationDatetime; // "2009-08-23T03:58:16+00:00"