Home > Backend Development > PHP Tutorial > PHP generates uuid format string example program_PHP tutorial

PHP generates uuid format string example program_PHP tutorial

WBOY
Release: 2016-07-13 10:48:04
Original
1233 people have browsed it

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

UUID refers to a number generated on one machine, which 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 number and many possible numbers. It is a combination of the following parts: 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 and the rest are the same), clock Sequence, a globally unique IEEE machine identification number (if there is a network card, it is obtained from the network card, if there is no network card, it is obtained in other ways). The only flaw of UUID is that the generated result string will be relatively long. The most commonly used UUID standard is Microsoft's GUID (Globals Unique Identifiers).
In ColdFusion, you can use the CreateUUID() function to easily generate a UUID. The format is: xxxxxxxx-xxxx-xxxx- xxxxxxxxxxxxxxxx(8-4-4-16), where each x is one in the range of 0-9 or a-f. Hexadecimal number. The standard UUID format is: xxxxxxxx-xxxx-xxxx-xxxxxx-xxxxxxxxxx (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(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(125);
// "}"
return $uuid;
}
}
?>

Copy code
function guid(){

If (function_exists('com_create_guid')){

          return com_create_guid();          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,12, 4).$hyphen                  .substr($charid,16, 4).$hyphen
                 .substr($charid,20,12)

                .chr(125);
// "}"
          return $uuid;
} <🎜> } <🎜> ?> http://www.bkjia.com/PHPjc/632819.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632819.htmlTechArticleWhat format is uuid? I think many friends don’t know, but you will probably know it already. It’s uuid. Let’s take a look at how to generate a uuid string. UUID refers to...
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template