PHP code example of snortlin / nano-id

1. Go to this page and download the library: Download snortlin/nano-id 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/ */

    

snortlin / nano-id example snippets


use Snortlin\NanoId\NanoId;

$nanoId = NanoId::nanoId(); // "unQ87dO06B5B-Ybq2Aum5"

// Custom size, default = 21
$nanoId = NanoId::nanoId(16); // "6PUg-8nn5IQrvKNw"

// Custom size and alphabet
$nanoId = NanoId::nanoId(16, '0123456789abcdef'); // "58b141975c2b72f3"

use Snortlin\NanoId\NanoId;

// Default size (21), numbers (0123456789)
$nanoId = NanoId::nanoId(NanoId::SIZE_DEFAULT, NanoId::ALPHABET_NUMBERS); // "782295634533276321176"

// Custom size, numbers and English alphabet without unreadable letters: 1, l, I, 0, O, o, u, v, 5, S, s, 2, Z
$nanoId = NanoId::nanoId(12, NanoId::ALPHABET_ALPHA_NUMERIC_READABLE); // "AcFQM9X3pCi8"


use Snortlin\NanoId\NanoId;

$nanoId = NanoId::nanoIdNonSecure();

// Custom size, default = 21
$nanoId = NanoId::nanoIdNonSecure(16);

// Custom size and alphabet
$nanoId = NanoId::nanoIdNonSecure(16, '0123456789abcdef');