Home  >  Article  >  Backend Development  >  PHP generated GUID (UUID)

PHP generated GUID (UUID)

WBOY
WBOYOriginal
2016-07-25 08:46:062256browse

PHP generated GUID (UUID)
  1. /**
  2.      * 生成GUID(UUID)
  3.      * @access public
  4.      * @return string
  5.      * @author knight
  6.      */
  7.     function createGuid()
  8.     {
  9.         if (function_exists('com_create_guid')){
  10.             return com_create_guid();
  11.         }else{
  12.             mt_srand((double)microtime()*10000);
  13.             $charid = strtoupper(md5(uniqid(rand(), true)));
  14.             $hyphen = chr(45);// "-"
  15.             $uuid = chr(123)// "{"
  16.                 .substr($charid, 0, 8).$hyphen
  17.                 .substr($charid, 8, 4).$hyphen
  18.                 .substr($charid,12, 4).$hyphen
  19.                 .substr($charid,16, 4).$hyphen
  20.                 .substr($charid,20,12)
  21.                 .chr(125);// "}"
  22.             return $uuid;
  23.         }
  24.     }
复制代码




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn