Skip to content

Instantly share code, notes, and snippets.

@parijke
Created August 3, 2022 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parijke/e6a785a844c9af10ad15c95979ab13fb to your computer and use it in GitHub Desktop.
Save parijke/e6a785a844c9af10ad15c95979ab13fb to your computer and use it in GitHub Desktop.
<?php
// Enter your code here, enjoy!
function gen_uuid($len=8) {
$hex = md5("this is my SALT" . uniqid("", true));
$pack = pack('H*', $hex);
$tmp = base64_encode($pack);
$uid = preg_replace("#(*UTF8)[^A-Za-z0-9]#", "", $tmp);
$len = max(4, min(128, $len));
while (strlen($uid) < $len)
$uid .= gen_uuid(22);
return substr($uid, 0, $len);
}
echo gen_uuid(8);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment