PHP GUID / UUID
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP GUID / UUID相关的知识,希望对你有一定的参考价值。
/**
* Defines the guid function
*
* @category functions
* @package skeleton
* @author Rob Brown <brownrl@gmail.com>
* @license http://www.gnu.org/philosophy/free-sw.html GPL Free
* @link http://www.itsgotto.be/cv.php
*/
/**
* Generate a uuid
*
* Generate a UUID taken from a web page that said this was the way to do it.
*
*
* @return string A uuid
*/
function guid() {
if (function_exists('com_create_guid')) {
return trim(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;
}
}
以上是关于PHP GUID / UUID的主要内容,如果未能解决你的问题,请参考以下文章
Excel生成guid、uuid
PHP生成 GUID全球唯一标识符
如何创建 GUID/UUID
如何测试有效的 UUID/GUID?
如何将 NEWID() / GUID / UUID 插入代码编辑器?
聊聊用 UUID/GUID 作为主键那些坑