Last active
August 29, 2015 14:13
-
-
Save MattKetmo/985b7dace430b58c3908 to your computer and use it in GitHub Desktop.
Uuid representation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
use Rhumsaa\Uuid\Uuid; | |
function printId(Uuid $uuid) { | |
$asString = $uuid->toString(); | |
$base64 = preg_replace('/==$/', '', base64_encode($uuid->getBytes())); | |
echo sprintf( | |
'%s (%d) => %s (%d)', | |
$asString, | |
strlen($asString), | |
$base64, | |
strlen($base64) | |
).PHP_EOL; | |
} | |
printId(Uuid::uuid1()); | |
printId(Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net')); | |
printId(Uuid::uuid4()); | |
printId(Uuid::uuid5(Uuid::NAMESPACE_DNS, 'php.net')); | |
// Output: | |
// 71c8851a-9a55-11e4-8e91-7831c1cda656 (36) => cciFGppVEeSOkXgxwc2mVg (22) | |
// 11a38b9a-b3da-360f-9353-a5a725514269 (36) => EaOLmrPaNg+TU6WnJVFCaQ (22) | |
// 6c18d72a-1b7e-4afa-9bc1-1b1f5d34d7ce (36) => bBjXKht+SvqbwRsfXTTXzg (22) | |
// c4a760a8-dbcf-5254-a0d9-6a4474bd1b62 (36) => xKdgqNvPUlSg2WpEdL0bYg (22) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment