1 /** 2 * 生成不带横杠的UUID 3 * @return string 4 */ 5 public static function genuuid() 6 { 7 return sprintf('%04x%04x%04x%04x%04x%04x%04x%04x', 8 // 32 bits for "time_low" 9 mt_rand(0, 0xffff), mt_rand(0, 0xffff), 10 11 // 16 bits for "time_mid" 12 mt_rand(0, 0xffff), 13 14 // 16 bits for "time_hi_and_version", 15 // four most significant bits holds version number 4 16 mt_rand(0, 0x0fff) | 0x4000, 17 18 // 16 bits, 8 bits for "clk_seq_hi_res", 19 // 8 bits for "clk_seq_low", 20 // two most significant bits holds zero and one for variant DCE1.1 21 mt_rand(0, 0x3fff) | 0x8000, 22 23 // 48 bits for "node" 24 mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) 25 ); 26 }