Sep 082010
Generate UUID in PHP
Answer:
To generate UUID in PHP, you can try the script below:
<?php
function uuid($prefix = '') {
$chars = md5(uniqid(mt_rand(), true));
$uuid = substr($chars,0,8) . '-';
$uuid .= substr($chars,8,4) . '-';
$uuid .= substr($chars,12,4) . '-';
$uuid .= substr($chars,16,4) . '-';
$uuid .= substr($chars,20,12);
return $prefix . $uuid;
}
echo uuid();
It shows something like the following when executed:
c664b9b4-6c44-c8d9-acf9-93ef0e11e435