This PHP library provides functions for generating RFC 4122 version 4 "universally unique" identifiers and for converting the standard 36-character format to and from a more compact but still-portable 26-character format.
These unique identifiers may be used, for example, to create unique database record ids across multiple related servers.
Functions
kcs_uuid4($prefix = '', $sep = '-')
This function creates an RFC 4122 version 4 "universally unique" identifier. The optional $prefix value can be included as additional data for unique value generation. The optional $sep value is the separator used between parts of the resulting id. The default is '-', for conformance with the standard. An empty string may be supplied to generate an id without punctuation. An id is string of 32 hexadecimal (base 16) digits without punctuation, and an additional four characters with the standard '-' separator.
kcs_packuid($uuid = '', $prefix = '')
This function compresses 32 hexadecimal digits of a supplied RFC 4122-style id $uuid (optionally containing punctuation) into 26 base-32 digits. If no uuid is supplied (or is empty), a new one is first generated using kcs_uuid4 and the optional $prefix.
kcs_unpackuid($uuid, $sep = '-')
This function expands 26 base-32 digits into 32 hexadecimal digits with punctuation in RFC 4122 format.
Examples
$uuid = kcs_uuid4();
# c9751cc8-852a-424c-a6cd-1e2eb626e223
$kuid = kcs_packuid($uuid);
# S5THSJ455914S9PD3RQBC9Q24C
$uuid = kcs_unpackuid($kuid);
# c9751cc8-852a-424c-a6cd-1e2eb626e223
$uuid = kcs_uuid4('', '');
# fc1e317b65bf49d0968fa4cfda0f5099
$kuid = kcs_packuid();
# XTSQTBF1HD6KUBEHY8425X70KM
$uuid = kcs_unpackuid($kuid);
# f6b37d2d-e18b-4d3d-add1-fa0822f8e09d
$kuid = kcs_packuid($uuid);
# XTSQTBF1HD6KUBEHY8425X70KM