Home >Backend Development >PHP Tutorial >Sharing of custom functions to generate UUID in PHP_PHP tutorial
The full name of UUID is Universally unique identifier. It is an identifier that can be generated by any computer and does not require a central database. Management ensures that there is almost no chance of duplication. The value range of UUID is so large that it is said that every grain of sand in the world is assigned a UUID, and there will be no duplicates.
Recently changing the WordPress code requires the use of UUID. However, there is no function to generate UUID in PHP, so I had to write one myself.
3 4 56 |
if (!function_exists('com_create_guid')) {
function com_create_guid() {
return sprintf( ' x x- x- x- x- x x x',
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 )
);
}
}
|