欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php生成uuid_PHP教程

程序员文章站 2022-06-14 19:54:08
...
Java代码
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 {
$return .= dechex(mt_rand(0,15));
}
return $return;
}

function ensure_length(&$string, $length)

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

}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478677.htmlTechArticleJava代码 function create_guid() { $microTime = microtime(); list($a_dec, $a_sec) = explode( , $microTime); $dec_hex = dechex($a_dec* 1000000); $sec_hex = dechex($a_sec); ensure_l...