1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?php function uuid() { $chars = md5(uniqid(mt_rand(), true)); $uuid = substr ( $chars, 0, 8 ) . '-' . substr ( $chars, 8, 4 ) . '-' . substr ( $chars, 12, 4 ) . '-' . substr ( $chars, 16, 4 ) . '-' . substr ( $chars, 20, 12 ); return $uuid ; } echo uuid();
?>
|
另一种生成方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| function guid(){ if (function_exists('com_create_guid')){ return com_create_guid(); }else{ mt_srand((double)microtime()*10000); $charid = strtoupper(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 guid();
|