PHP generate UUID format string Instance program _php Tutorial

Source: Internet
Author: User
What is the format of the UUID string I think a lot of friends do not know, but you have already come to know what is the UUID, let's look at how to generate a UUID string.

A UUID is a number generated on a machine that guarantees that all machines in the same time and space are unique. Typically the platform provides the API to generate the UUID. The UUID is based on the standards established by the Open Software Foundation (OSF), using Ethernet card addresses, nanosecond-seconds, chip ID codes, and many possible numbers. A combination of the following: the current date and time (the first part of the UUID is related to the time, if you generate a UUID after a few seconds, the first part is different, the rest is the same), the clock sequence, the globally unique IEEE Machine identification number (if there is a network card, from the network card, No network cards are available in other ways, the only drawback to the UUID is that the resulting string will be longer. The most common use of UUID for this standard is the GUID of Microsoft (Globals Unique Identifiers).
In ColdFusion, the UUID can be easily generated using the Createuuid () function in the form of: Xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx (8-4-4-16), where each x is 0-9 or a-f A hexadecimal number within the range. The standard UUID format is: xxxxxxxx-xxxx-xxxx-xxxxxx-xxxxxxxxxx (8-4-4-4-12)

The code is as follows Copy Code

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 (123)
// "{"
. substr ($charid, 0, 8). $hyphen
. substr ($charid, 8, 4). $hyphen
. substr ($charid, 4). $hyphen
. substr ($charid, 4). $hyphen
. substr ($charid, 20,12)
. chr (125);
// "}"
return $uuid;
}
}
?>

http://www.bkjia.com/PHPjc/632819.html www.bkjia.com true http://www.bkjia.com/PHPjc/632819.html techarticle what is the format of the UUID string I think a lot of friends do not know, but you have already come to know what is the UUID, let's look at how to generate a UUID string. The UUID refers to ...

  • Related Article

    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.