php生成uuid(guid)

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();
//生成后格式82796f26-ee3c-f32d-997f-42479f66f8ff
?>

另一种生成方法:

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);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid =// chr(123)
substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
//.chr(125);
return $uuid;
}
}
echo guid();

🔰本文标题: php生成uuid(guid)

🔞本文链接: https://193.gs/phpscuuid/index.html

🌡️本文总热度