PHPackages                             kuldippujara/nanoid-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kuldippujara/nanoid-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kuldippujara/nanoid-php
=======================

A copy of nanoid in PHP

1.1.6(7y ago)01.8k1MITPHPPHP ~5.5|~7.0

Since Sep 11Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kuldippujara/nanoid-php)[ Packagist](https://packagist.org/packages/kuldippujara/nanoid-php)[ Docs](https://github.com/hidehalo/nanoid-php)[ RSS](/packages/kuldippujara-nanoid-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (12)Used By (0)

Nanoid-php
==========

[](#nanoid-php)

[![Build Status](https://camo.githubusercontent.com/6e73fae483f97e9e2361aabf2f114abd3519767fb08f71244f5ebc854e780d89/68747470733a2f2f7472617669732d63692e6f72672f6869646568616c6f2f656d6f6a692e737667)](https://travis-ci.org/hidehalo/nanoid-php)

> A tiny (179 bytes), secure URL-friendly unique string ID generator for JavaScript
>
> **Safe.** It uses cryptographically strong random APIs and guarantees a proper distribution of symbols.
>
> **Small.** Only 179 bytes (minified and gzipped). No dependencies. It uses Size Limit to control size.
>
> **Compact.** It uses more symbols than UUID (A-Za-z0-9\_~) and has the same number of unique options in just 21 symbols instead of 36.

Thanks awesome [ai](https://github.com/ai) and his [nanoid](https://github.com/ai/nanoid), this package is a copy in PHP! If you like nanoid and you want to use it in PHP, try me :D

Install
-------

[](#install)

Via Composer

```
$composer require hidehalo/nanoid-php
```

Usage
-----

[](#usage)

### Normal

[](#normal)

> The main module uses URL-friendly symbols (A-Za-z0-9\_~) and returns an ID with 21 characters (to have the same collisions probability as UUID v4).

```
use Hidehalo\Nanoid\Client;
use Hidehalo\Nanoid\GeneratorInterface;

$client = new Client();

# default random generator
echo $client->generateId($size = 21);
# more safer random generator
echo $client->generateId($size = 21, $mode = Client::MODE_DYNAMIC)
```

### Custom Alphabet or Length

[](#custom-alphabet-or-length)

```
echo $client->formatedId($alphabet = '0123456789abcdefg', $size = 21);
```

> Alphabet must contain 256 symbols or less. Otherwise, the generator will not be secure.

### Custom Random Bytes Generator

[](#custom-random-bytes-generator)

```
# PS: anonymous class is new feature when PHP_VERSION >= 7.0
echo $client->formatedId($alphabet = '0123456789abcdefg', $size = 21,
new class implements GeneratorInterface {
    /**
     * @inheritDoc
     */
    public function random($size)
    {
        //TODO: implemenation ...
    }
});
```

> `random` callback must accept the array size and return an array with random numbers.
>
> If you want to use the same URL-friendly symbols with `format`, you can get default alphabet from the `url` module:

Please see [`CoreInterface::random(...)`](src/CoreInterface.php) for the core random API prototype and notes

Examples
--------

[](#examples)

Please see [Examples](examples) for more information on detailed usage.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Notice
------

[](#notice)

If you have any issues, just feel free and open it in this repository, thx!

Credits
-------

[](#credits)

- [ai](https://github.com/ai)
- [hidehalo](https://github.com/hidehalo)
- [All Contributors](https://github.com/hidehalo/nanoid-php/graphs/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 93.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~44 days

Recently: every ~16 days

Total

10

Last Release

2769d ago

PHP version history (2 changes)1.0.0-alphaPHP ~5.6|~7.0

1.1.5PHP ~5.5|~7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f7ebbb7fd8d5bed650ff90bfa01d5c9962199a26d76f25439702a1ab92e4caf?d=identicon)[kuldippujara](/maintainers/kuldippujara)

---

Top Contributors

[![hidehalo](https://avatars.githubusercontent.com/u/6302952?v=4)](https://github.com/hidehalo "hidehalo (31 commits)")[![kuldippujara](https://avatars.githubusercontent.com/u/207179?v=4)](https://github.com/kuldippujara "kuldippujara (2 commits)")

---

Tags

hidehalonanoid-php

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/kuldippujara-nanoid-php/health.svg)

```
[![Health](https://phpackages.com/badges/kuldippujara-nanoid-php/health.svg)](https://phpackages.com/packages/kuldippujara-nanoid-php)
```

###  Alternatives

[hidehalo/nanoid-php

A copy of nanoid in PHP

8124.1M41](/packages/hidehalo-nanoid-php)[paragonie/random-lib

A Library For Generating Secure Random Numbers

703.3M26](/packages/paragonie-random-lib)[jasonhinkle/php-gpg

GPG / PGP port written in pure PHP with no binary dependencies

116147.2k1](/packages/jasonhinkle-php-gpg)[gpslab/base64uid

Generate UID like YouTube

68103.4k](/packages/gpslab-base64uid)[wyrihaximus/react-child-process-messenger

Messenger decorator for react/child-process

32279.4k4](/packages/wyrihaximus-react-child-process-messenger)[andrewcarteruk/cryptokey

A command line tool for generating keys using a CSPRNG.

6124.2k](/packages/andrewcarteruk-cryptokey)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
