PHP生成唯一字符串

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/flightsmallbird/article/details/74315713

//guid方法

  1. function guid() {    
  2.     if (function_exists('com_create_guid')) {        
  3.         return com_create_guid();    
  4.     } else {     
  5.         mt_srand((double)microtime()*10000);
  6.         $charid = strtoupper(md5(uniqid(rand(), true))); 
  7.         $hyphen = chr(45);        
  8.         $uuid   = chr(123)            
  9.                  .substr($charid, 0, 8).$hyphen               
  10.                  .substr($charid, 8, 4).$hyphen            
  11.                  .substr($charid,12, 4).$hyphen            
  12.                  .substr($charid,16, 4).$hyphen            
  13.                  .substr($charid,20,12)            
  14.                  .chr(125);
  15.         return $uuid;    
  16.     }
  17. }

生成订单号

  1. function build_order_no() {    
  2.     return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
  3. }

猜你喜欢

转载自blog.csdn.net/flightsmallbird/article/details/74315713