visus/cuid2

A PHP library for generating collision-resistant ids (CUIDs).

5.0.0 2024-12-09 11:41 UTC

This package is auto-updated.

Last update: 2024-12-10 19:45:43 UTC


README

GitHub Workflow Status (with event)

Sonar Quality Gate Sonar Coverage Sonar Tests

PHP Version Packagist Downloads GitHub

A PHP implementation of collision-resistant ids. You can read more about CUIDs from the official project website.

Getting Started

You can install visus/cuid2 as a composer package:

Important

The PHP extension GMP is required in order to use this library.

composer require visus/cuid2

Quick Example

<?php
require_once 'vendor/autoload.php';

// new (default length of 24)
$cuid = new Visus\Cuid2\Cuid2();

// implicit casting
echo $cuid; // apr5hhh4ox45krsg9gycbs9k

// explicit casting
echo $cuid->toString(); // apr5hhh4ox45krsg9gycbs9k

// new (with custom length)
$cuid = new Visus\Cuid2\Cuid2(10);
echo $cuid; // pekw02xwsd