- substr: documentation ( source)
- time: documentation ( source)
- mt_rand: documentation ( source)
- sprintf: documentation ( source)
<?php
function uuid() {
$x4 = function() {
for ($n = ''; strlen($n) < 5; $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();