zoukankan      html  css  js  c++  java
  • PHP 生成UUID的方法

     1 public function guid(){
     2     //检测是否存在函数
     3     if (function_exists('com_create_guid')){
     4         //创建全局唯一UUID标识.
     5         return com_create_guid();
     6     } else {
     7         //随机数生成器. php4.2.0以上版本支持.
     8         mt_srand((double)microtime() * 10000);
     9         //基于以微秒计的当前时间,生成一个唯一的 ID
    10         $unid = uniqid(rand(), true);
    11         //将字符串转换为大写.
    12         $charid = strtoupper(md5$unid ));
    13         // 从指定的 ASCII 值返回字符 "-"
    14         $hyphen = chr(45);
    15         // 从指定的 ASCII 值返回字符 "{"
    16         $uuid = chr(123).substr($charid, 0, 8)
    17                 .$hyphen.substr($charid, 8, 4)
    18                 .$hyphen.substr($charid,12, 4)
    19                 .$hyphen.substr($charid,16, 4)
    20                 .$hyphen.substr($charid,20,12)
    21                 .chr(125);// 从指定的 ASCII 值返回字符 "}"
    22         return $uuid;
    23     }
    24 }
  • 相关阅读:
    4.比赛F
    4.M
    4.H
    4.J
    4.G
    4.D
    4.C
    UVA 215 Spreadsheet Calculator (模拟)
    POJ 3469 Dual Core CPU(最小割模型的建立)
    POJ 3281 Dining(网络流最大匹配)
  • 原文地址:https://www.cnblogs.com/mcqueen/p/4029775.html
Copyright © 2011-2022 走看看