Php generate uuid format string instances_php tutorial

Source: Internet
Author: User
Php generates a uuid format string instance program. Uuid is a string in what format I think many of my friends don't know, but you have come to estimate what uuid is. let's take a look at how to generate a uuid string. UUID refers to the uuid in what format. I don't think many of you know about it, but you have come to estimate what uuid is. let's take a look at how to generate a uuid string.

UUID refers to the number generated on a machine, which ensures that all machines in the same time and space are unique. Generally, the platform provides APIs for UUID generation. UUID is calculated according to the standards set by the Open Software Foundation (OSF), and uses Ethernet card addresses, nanoseconds, chip ID codes, and many possible numbers. The combination of the following parts: the current date and time (the first part of UUID is related to the time. if you generate a UUID in seconds, the first part is different and the rest are the same), the clock sequence, and the globally unique IEEE machine identification number (if there is a Nic, it is obtained from the NIC, and no Nic is obtained in other ways ), the unique defect of UUID is that the generated result string is long. The most common UUID standard is Microsoft's GUID (Globals Unique Identifiers ).
In ColdFusion, you can use the CreateUUID () function to generate a UUID in the format of xxxxxxxx-xxxx-xxxxxxxxxxxxxxxx (8-4-4-16 ), each x is a hexadecimal number in the range of 0-9 or a-f. The standard UUID format is: xxxxxxxx-xxxx-xxxxxx-XXXXXXXXXXXX (8-4-4-4-12)

The code is as follows:

Function guid (){
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 = chr (1, 123)
//"{"
. Substr ($ charid, 0, 8). $ hyphen
. Substr ($ charid, 8, 4). $ hyphen
. Substr ($ charid, 12, 4). $ hyphen
. Substr ($ charid, 16, 4). $ hyphen
. Substr ($ charid, 20, 12)
. Chr (1, 125 );
//"}"
Return $ uuid;
}
}
?>

Bytes. UUID refers...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.