PHP生成UUID的方法有哪些?
- 内容介绍
- 文章标签
- 相关推荐
本文共计100个文字,预计阅读时间需要1分钟。
phpfunction uuid($prefix='') { $str=uniqid('', true); $arr=explode('.', $str); $str=$prefix . base_convert($arr[0], 16, 36) . base_convert($arr[1], 10, 36) . base_convert(bin2hex(random_bytes(5)), 16, 36); $len=24; $str=substr($str, 0, $len); return $str;}
php uuidfunction uuid($prefix = ''){ $str = uniqid('',true); $arr = explode('.',$str); $str = $prefix.base_convert($arr[0],16,36).base_convert($arr[1],10,36).base_convert(bin2hex(random_bytes(5)),16,36); $len = 24; $str = substr($str,0,$len); if(strlen($str) < $len){ $mt = base_convert(bin2hex(random_bytes(5)),16,36); $str = $str.substr($mt,0,$len - strlen($str)); } return $str; } // return 6x84e9pbro319qu68b9alda6
本文共计100个文字,预计阅读时间需要1分钟。
phpfunction uuid($prefix='') { $str=uniqid('', true); $arr=explode('.', $str); $str=$prefix . base_convert($arr[0], 16, 36) . base_convert($arr[1], 10, 36) . base_convert(bin2hex(random_bytes(5)), 16, 36); $len=24; $str=substr($str, 0, $len); return $str;}
php uuidfunction uuid($prefix = ''){ $str = uniqid('',true); $arr = explode('.',$str); $str = $prefix.base_convert($arr[0],16,36).base_convert($arr[1],10,36).base_convert(bin2hex(random_bytes(5)),16,36); $len = 24; $str = substr($str,0,$len); if(strlen($str) < $len){ $mt = base_convert(bin2hex(random_bytes(5)),16,36); $str = $str.substr($mt,0,$len - strlen($str)); } return $str; } // return 6x84e9pbro319qu68b9alda6

