標籤:style color os io 使用 ar for cti sp
<?php
UUID是指在一台機器上產生的數字,它保證對在同一時空中的所有機器都是唯一的。通常平台 會提供產生UUID的API。UUID按照開放軟體基金會(OSF)制定的標準計算,用到了乙太網路卡地址、納秒級時間、晶片ID碼和許多可能的數字。由以 下幾部分的組合:當前日期和時間(UUID的第一個部分與時間有關,如果你在產生一個UUID之後,過幾秒又產生一個UUID,則第一個部分不同,其餘相 同),時鐘序列,全域唯一的IEEE機器識別號(如果有網卡,從網卡獲得,沒有網卡以其他方式獲得),UUID的唯一缺陷在於產生的結果串會比較長。關於 UUID這個標準使用最普遍的是微軟的GUID(Globals Unique Identifiers)。
在ColdFusion中可以用CreateUUID()函數很簡單的產生UUID,其格式為:xxxxxxxx-xxxx-xxxx- xxxxxxxxxxxxxxxx(8-4-4-16),其中每個 x 是 0-9 或 a-f 範圍內的一個十六進位的數字。而標準的UUID格式為:xxxxxxxx-xxxx-xxxx-xxxxxx-xxxxxxxxxx (8-4-4-4-12)
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)的方法