uuid生成_php如何生成 uuid(总结)
生活随笔
收集整理的這篇文章主要介紹了
uuid生成_php如何生成 uuid(总结)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、UUID的格式是什么?
UUID格式為:xxxxxxxx-xxxx-xxxx-xxxxxx-xxxxxxxxxx (8-4-4-4-12),其中每個 x 是 0-9 或 a-f 范圍內的一個十六進制的數字
2、UUID使用實例?
用md5函數生成密碼字符串,然后substr函數在里面截取就好:md5(uniqid(mt_rand(), true));
<?phpnamespace AppModelTools;use IlluminateDatabaseEloquentModel;class UUID extends Model {public static function create_uuid($prefix=""){$chars = md5(uniqid(mt_rand(), true));$uuid = substr ( $chars, 0, 8 ) . '-'. substr ( $chars, 8, 4 ) . '-'. substr ( $chars, 12, 4 ) . '-'. substr ( $chars, 16, 4 ) . '-'. substr ( $chars, 20, 12 );return $prefix.$uuid ;} }3、php的UUID擴展?
UUID extension
二、php生成唯一識別碼uuid
/*生成唯一標志 *標準的UUID格式為:xxxxxxxx-xxxx-xxxx-xxxxxx-xxxxxxxxxx(8-4-4-4-12) */function uuid() { $chars = md5(uniqid(mt_rand(), true)); $uuid = substr ( $chars, 0, 8 ) . '-'. substr ( $chars, 8, 4 ) . '-' . substr ( $chars, 12, 4 ) . '-'. substr ( $chars, 16, 4 ) . '-'. substr ( $chars, 20, 12 ); return $uuid ; } echo uuid(); //Returns like 'dba5ce3e-430f-cf1f-8443-9b337cb5f7db'三、laravel中uuid使用實例
<?phpnamespace AppModelTools;use IlluminateDatabaseEloquentModel;class UUID extends Model {public static function create_uuid($prefix=""){$chars = md5(uniqid(mt_rand(), true));$uuid = substr ( $chars, 0, 8 ) . '-'. substr ( $chars, 8, 4 ) . '-'. substr ( $chars, 12, 4 ) . '-'. substr ( $chars, 16, 4 ) . '-'. substr ( $chars, 20, 12 );return $prefix.$uuid ;} }以上內容希望幫助到大家,很多PHPer在進階的時候總會遇到一些問題和瓶頸,業務代碼寫多了沒有方向感,不知道該從那里入手去提升,對此我整理了一些資料,包括但不限于:分布式架構、高可擴展、高性能、高并發、服務器性能調優、TP6,laravel,YII2,Redis,Swoole、Swoft、Kafka、Mysql優化、shell腳本、Docker、微服務、Nginx等多個知識點高級進階干貨需要的可以免費分享給大家,需要戳這里PHP進階架構師>>>視頻、面試文檔免費獲取
或 者關注我每天分享技術文章
PHP進階編程?www.zhihu.com總結
以上是生活随笔為你收集整理的uuid生成_php如何生成 uuid(总结)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 知识图谱入门知识(四)NER详解
- 下一篇: python创建socket对象_pyt