progNewbie
progNewbie

Reputation: 4822

PHP: How to generate a GUID as char 22?

I generate my GUIDs like this:

public static function getGUID(){
        if (function_exists('com_create_guid')){
            return 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);// "-"
            $uuid = substr($charid, 0, 8).$hyphen
            .substr($charid, 8, 4).$hyphen
            .substr($charid,12, 4).$hyphen
            .substr($charid,16, 4).$hyphen
            .substr($charid,20,12);
            return $uuid;
        }
    }

But for the API I am using, I need to get an GUID as char 22. How do I do this?

It should look like this:

051MWsLH7jMaiuTyaRbC80

Upvotes: 3

Views: 598

Answers (1)

Denis Alimov
Denis Alimov

Reputation: 2901

22 char UUID is called XUID. see instructions how to make XUID from UUID here also there is a link to PHP library to generate XUID

Upvotes: 3

Related Questions