Created
August 3, 2022 10:23
-
-
Save parijke/e6a785a844c9af10ad15c95979ab13fb to your computer and use it in GitHub Desktop.
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 | |
// 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