- substr: documentation ( source)
- time: documentation ( source)
- mt_rand: documentation ( source)
- sprintf: documentation ( source)
<?php
function uuid() {
$x4 = function() {
$n = '';
while (strlen($n) < 4) {
$n = $n.mt_rand();
}
return substr($n, -4);
};
return sprintf(
'%s-%04d-%04d-%04d-%04d%04d%04d',
time(), $x4(), $x4(), $x4(), $x4(), $x4(), $x4(), $x4()
);
}
echo uuid();