Skip to content

Instantly share code, notes, and snippets.

@lmammino
Created January 31, 2014 12:06
Show Gist options
  • Save lmammino/8730841 to your computer and use it in GitHub Desktop.
Save lmammino/8730841 to your computer and use it in GitHub Desktop.
Create unique ids with Php
<?php
function gen_uuid($len=8) {
$hex = md5("yourSaltHere" . 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment