1. Homepage
  2. Articoli
  3. Video
  4. Bash scripting
  5. Sistema
  6. Tips
  7. News


Simple UUID with php

» Author: Andrea Ganduglia Date: 2010-11-27 12:54:54 Copyright: (c)2010 Andrea Ganduglia

function uuidgen(){
    #xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
    $y = Array('8','9','a','b');
    $uuid = md5(uniqid(mt_rand(),true));
    $uuid = substr($uuid,0,8)."-".substr($uuid,8,4)."-".substr($uuid,12,4)."-".substr($uuid,16,4)."-".substr($uuid,20,12);
    $uuid[14] = 4;
    $uuid[19] = $y[rand(0,3)];
    return $uuid;
}
8e7363e6-1222-4945-a3c2-b79c5e0cab39