Skip to content

Instantly share code, notes, and snippets.

@rahenrique
Last active December 4, 2020 17:09
Show Gist options
  • Save rahenrique/59bfd1f0ed00ea9fa0efe6a0bb824dde to your computer and use it in GitHub Desktop.
Save rahenrique/59bfd1f0ed00ea9fa0efe6a0bb824dde to your computer and use it in GitHub Desktop.
GUID em PHP útil para criação de identificadores únicos
<?php
function getGUID(){
mt_srand((double)microtime()*10000);
$charid = strtolower(md5(uniqid(rand(), true)));
$hyphen = chr(45);
$uuid = substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
return $uuid;
}
echo getGUID();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment