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