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