Skip to content

Instantly share code, notes, and snippets.

@juanjosezg
Created June 25, 2018 19:57
Show Gist options
  • Save juanjosezg/021cf650cbf1fc90fc5c7a12c2519371 to your computer and use it in GitHub Desktop.
Save juanjosezg/021cf650cbf1fc90fc5c7a12c2519371 to your computer and use it in GitHub Desktop.
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