macx/rfc-4122-uuid

There is no license information available for the latest version (1.0.0) of this package.

PHP-Class to generate valid RFC 4122 compliant Universally Unique IDentifiers (UUID) version 3, 4 and 5.

1.0.0 2014-10-14 11:34 UTC

This package is not auto-updated.

Last update: 2024-04-23 00:17:25 UTC


README

The following class generates VALID RFC 4122 COMPLIANT Universally Unique IDentifiers (UUID) version 3, 4 and 5.

UUIDs generated validates using OSSP UUID Tool, and output for named-based UUIDs are exactly the same. This is a pure PHP implementation.

Author: Andrew Moore posted this as a note at the PHP Manual back in 2010.

Install

If you're using Composer as a package manager for PHP, put this require directive in your composer.json and run composer install in your CLI.

{
  "require" : {
    "macx/rfc-4122-uuid" : "1.0.*"
  }
}

Or require it via command line with:

$ composer require macx/rfc-4122-uuid 1.0.*

Generate a unique ID

To generate a ID simply copy the following code:

include 'vendor/autoload.php';

$uuid = macx\UUID::v4();

echo 'The generated UUID is `' . $uuid . '`';

If you want to validate a ID against RFC do this:

$givenId = 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6';

if(macx\UUID::is_valid($givenId)) {
  // do something
}