uuid is a PHP module for generating UUIDs. It can be installed from PECL with the following command:
sudo pecl install uuid
Creates a UUID based on a passed type:
- UUID_TYPE_DEFAULT (0)
- UUID_TYPE_TIME (1)
- UUID_TYPE_RANDOM (4)
$uuid = uuid_create(UUID_TYPE_RANDOM);
echo $uuid; // => "a04e572a-0612-4519-8450-c6f64adb0be1"
- UUID_TYPE_INVALID (-42)
- UUID_TYPE_DCE (4)
- UUID_TYPE_NAME (1)
Tells if provided UUID is valid.
uuid_is_valid('a04e572a-0612-4519-8450-c6f64adb0be1'); // => true
uuid_is_valid('foo-bar'); // => false
Tell if two UUIDs match.
$uuid = 'a04e572a-0612-4519-8450-c6f64adb0be1';
$another_uuid = '98ed652b-f6a2-4c68-a8c6-815f50657a57';
uuid_compare($uuid, $uuid); // => true
uuid_compare($uuid, $another_uuid); // => false
Tells if a provided UUID is of null type (UUID_TYPE_NULL (-1)). This kind of UUID contains all zeros instead of other hexadecimal values.
$null_uuid = '00000000-0000-0000-0000-000000000000';
uuid_is_null($null_uuid); // => true
$uuid = 'a04e572a-0612-4519-8450-c6f64adb0be1';
uuid_compare($uuid, $uuid); // => false
Returns the type of the provided UUID.
$time_uuid = '1ed0df7a-a009-11e3-b19b-2b3fc91c18ca';
uuid_type($time_uuid); // => 2
$rand_uuid = 'a04e572a-0612-4519-8450-c6f64adb0be1';
uuid_type($rand_uuid); // => 4
Returns a UUID variant which can be any of these values:
- UUID_VARIANT_DCE (1) - Unix-like UUID variant
- UUID_VARIANT_MICROSOFT (2) - Windows UUID variant
- UUID_VARIANT_OTHER (3) - Other OS UUID variant
$uuid = '1ed0df7a-a009-11e3-b19b-2b3fc91c18ca';
uuid_variant($uuid); // => 1
Returns a Unix timestamp from a UUID of time type.
$time_uuid = 'b8674158-a00c-11e3-aa3f-ab179b870a60';
uuid_time($uuid); // => 1393546224
$rand_uuid = '1ed0df7a-a009-11e3-b19b-2b3fc91c18ca';
uuid_time($uuid); // => false
Returns a MAC address from UUID. No code samples available yet.
Translates a UUID to 16 byte binary.
uuid_parse('06b46301-0a4d-4096-afb3-270de248e46b'); // => "��c� M@���' �H�k"
Translates a parsed UUID to its original form. See uuid_parse.
uuid_unparse('�c� M@���' �H�k'); // => "06b46301-0a4d-4096-afb3-270de248e46b�"