Generate Nano ID using PHP

hidehalo/nanoid-php library

  1. Add hidehalo/nanoid-php library to composer.json file:
"require": {
    "hidehalo/nanoid-php": "^1.1"
}
  1. Install library from the command line:
composer install
  1. Generate Nano ID:
<?php

require_once __DIR__.'/vendor/autoload.php';

use Hidehalo\Nanoid\Client;

$client = new Client();

$nanoIdStr = $client->generateId();
echo $nanoIdStr.PHP_EOL;

$nanoIdStr = $client->formatedId('0123456789abc', 10);
echo $nanoIdStr.PHP_EOL;

Leave a Comment

Cancel reply

Your email address will not be published.