首页 > Web开发 > 详细

php 生成 guid

时间:2018-09-11 13:46:15      阅读:182      评论:0      收藏:0      [点我收藏+]
function guid( $opt = true ){       //  Set to true/false as your default way to do this.
    if( function_exists(‘com_create_guid‘) ){
        if( $opt ){ return com_create_guid(); }
            else { return trim( com_create_guid(), ‘{}‘ ); }
        }
        else {
            mt_srand( (double)microtime() * 10000 );    // optional for php 4.2.0 and up.
            $charid = strtoupper( md5(uniqid(rand(), true)) );
            $hyphen = chr( 45 );    // "-"
            $left_curly = $opt ? chr(123) : "";     //  "{"
            $right_curly = $opt ? chr(125) : "";    //  "}"
            $uuid = $left_curly
                . substr( $charid, 0, 8 ) . $hyphen
                . substr( $charid, 8, 4 ) . $hyphen
                . substr( $charid, 12, 4 ) . $hyphen
                . substr( $charid, 16, 4 ) . $hyphen
                . substr( $charid, 20, 12 )
                . $right_curly;
            return $uuid;
            }
}

php 生成 guid

原文:https://www.cnblogs.com/xiaoyucoding/p/9626914.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!