Created
June 25, 2018 19:57
-
-
Save juanjosezg/021cf650cbf1fc90fc5c7a12c2519371 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function struuid($entropy) | |
{ | |
$s=uniqid("",$entropy); | |
$num= hexdec(str_replace(".","",(string)$s)); | |
$index = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; | |
$base= strlen($index); | |
$out = ''; | |
for($t = floor(log10($num) / log10($base)); $t >= 0; $t--) { | |
$a = floor($num / pow($base,$t)); | |
$out = $out.substr($index,$a,1); | |
$num = $num-($a*pow($base,$t)); | |
} | |
return $out; | |
} | |
echo struuid(false); //Return sample: P3YCAU6EY2 | |
echo struuid(true); //Return sample: N5YQLFG922EFW7JDE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment