How should I create my GUID?

前端 未结 3 1063
[愿得一人]
[愿得一人] 2021-02-13 16:57

I\'m going to be uploading images to a system and need them to be referenced by a non-sequential unique ID. I\'ve read a little about GUIDs, and I\'m wondering what the best app

3条回答
  •  梦毁少年i
    2021-02-13 17:24

    I also want to create guid for calling .net api and this function generate a key in guid format and it works for me

    function generateGuid($include_braces = false) {
        if (function_exists('com_create_guid')) {
            if ($include_braces === true) {
                return com_create_guid();
            } else {
                return substr(com_create_guid(), 1, 36);
            }
        } else {
            mt_srand((double) microtime() * 10000);
            $charid = strtoupper(md5(uniqid(rand(), true)));
    
            $guid = substr($charid,  0, 8) . '-' .
                    substr($charid,  8, 4) . '-' .
                    substr($charid, 12, 4) . '-' .
                    substr($charid, 16, 4) . '-' .
                    substr($charid, 20, 12);
    
            if ($include_braces) {
                $guid = '{' . $guid . '}';
            }
    
            return $guid;
        }
    }
    

提交回复
热议问题