Home  >  Article  >  Backend Development  >  PHP generates uuid format string example program

PHP generates uuid format string example program

高洛峰
高洛峰Original
2016-11-29 15:16:481152browse

What format is uuid? I think many friends don’t know, but you’ve already come here and you probably know what uuid is. Let’s take a look at how to generate a uuid string.

UUID refers to the The number generated on the machine is guaranteed to be unique to all machines in the same time and space. Usually the platform will provide an API to generate UUID. The UUID is calculated according to the standards set by the Open Software Foundation (OSF), using the Ethernet card address, nanosecond time, chip ID code and many possible numbers.

is a combination of the following parts: the current date and time (UUID The first part is related to time. If you generate a UUID after a few seconds, the first part is different and the rest are the same.), clock sequence, globally unique IEEE machine identification number (if there is a network card, Obtained from the network card (no network card can be obtained in other ways), the only flaw of UUID is that the generated result string will be relatively long. The most commonly used standard for UUID is Microsoft's GUID (Globals Unique Identifiers).

Can be used in ColdFusion The CreateUUID() function simply generates a UUID in the format: xxxxxxxx-xxxx-xxxx- xxxxxxxxxxxxxxxx (8-4-4-16), where each x is a hexadecimal number in the range of 0-9 or a-f. Number, and the standard UUID format is: xxxxxxxx-xxxx-xxxx-xxxxxx-xxxxxxxxxx (8-4-4-4-12)

php generates a uuid format string example program code as follows:

function guid(){

if (function_exists('com_create_guid')){ return com_create_guid();

}else{

mt_srand((d ouble)microtime()*10000);

//optional for php 4.2.0 and up.

           $charid = strtoupper(md5(uniqid(rand(), true))); $uuid = chr (123)

// "{"

                              .            .substr($charid,12, 4).$hyphen

                                           . 25);

// "}" //Open source Code phpfensi.com

                                                                                      return $uuid;                                                                                     

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn