macx / rfc-4122-uuid
PHP-Class to generate valid RFC 4122 compliant Universally Unique IDentifiers (UUID) version 3, 4 and 5.
Installs: 6 751
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-12-17 03:46:08 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 }