PHP Build UUID Custom Function Share _php tutorial

Source: Internet
Author: User
Tags 04x uuid

Generate UUID Custom function sharing in PHP


The UUID name is universally unique identifier, which is a identifier that can be generated using any computer, without the need for a central database to be managed, which guarantees almost no duplication of chances. The range of the UUID is said to assign a UUID to every grain of sand in the world, and there will be no repetition.

Recently in the code to change WordPress, need to use the UUID. However, PHP does not actually generate UUID function, had to write a.

1

2

3

4

5

6

7

8

9

10

11

if (!function_exists (' Com_create_guid ')) {

function Com_create_guid () {

return sprintf ('%04x%04x-%04x-%04x-%04x-%04x%04x%04x ',

Mt_rand (0, 0xFFFF), Mt_rand (0, 0xFFFF),

Mt_rand (0, 0xFFFF),

Mt_rand (0, 0X0FFF) | 0x4000

Mt_rand (0, 0X3FFF) | 0x8000

Mt_rand (0, 0xFFFF), Mt_rand (0, 0xFFFF), Mt_rand (0, 0xFFFF)

);

}

}

The code above can generate a UUID version 4. UUID currently has 5 versions, of which the fourth version is completely random and easy to generate. The Com_create_guid, which is a function of PHP in Windows, directly calls COM's createguid function to generate the UUID, but there is no corresponding library of functions in Linux, so I have to write it by myself. To facilitate use on different platforms, a function with the same name has been created. The other code is to generate random numbers.

As for usage, call Com_create_guid () directly.

http://www.bkjia.com/PHPjc/1014275.html www.bkjia.com true http://www.bkjia.com/PHPjc/1014275.html techarticle generate UUID Custom function in PHP shared UUID full name is universally unique identifier, it is a identifier, use any computer can be generated, do not need a central database into ...

  • 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.