php 生成 uuid_PHP_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > PHP > php 生成 uuid

php 生成 uuid

 2011/8/24 8:11:58  man_yutao  http://man-yutao.iteye.com  我要评论(0)
  • 摘要:functioncreate_guid(){$microTime=microtime();list($a_dec,$a_sec)=explode("",$microTime);$dec_hex=dechex($a_dec*1000000);$sec_hex=dechex($a_sec);ensure_length($dec_hex,5);ensure_length($sec_hex,6);$guid="";$guid.=$dec_hex;$guid.=create_guid_section(3
  • 标签:PHP
function create_guid()
{
$microTime = microtime();
list($a_dec, $a_sec) = explode(" ", $microTime);
$dec_hex = dechex($a_dec* 1000000);
$sec_hex = dechex($a_sec);
ensure_length($dec_hex, 5);
ensure_length($sec_hex, 6);
$guid = "";
$guid .= $dec_hex;
$guid .= create_guid_section(3);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= create_guid_section(4);
$guid .= '-';
$guid .= $sec_hex;
$guid .= create_guid_section(6);
return $guid;
}
function create_guid_section($characters)
{
$return = "";
for($i=0; $i<$characters; $i++)
{
$return .= dechex(mt_rand(0,15));
}
return $return;
}

function ensure_length(&$string, $length)  

{  
    $strlen = strlen($string);  
   if($strlen < $length)  
   {  
        $string = str_pad($string,$length,"0");  
    }  
     else if($strlen > $length)  
   {  
         $string = substr($string, 0, $length);  
  }  

 }  
发表评论
用户名: 匿名