note 52354 added to function.com-create-guid
| From: | Kristof_Polleunis at yahoo dot com | Date: | Thu, 28 Apr 2005 15:16:44 +0000 |
| Subject: | note 52354 added to function.com-create-guid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88696@lists.php.net to get a copy of this message | ||
A guid function that works in all php versions:
<?php
function guid(){
if (function_exists('com_create_guid')){
return com_create_guid();
}else{
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12)
.chr(125);// "}"
return $uuid;
}
}
echo guid();
?>
----
Manual Page -- http://www.php.net/manual/en/function.com-create-guid.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52354
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52354&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52354&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52354&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52354&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52354&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52354&report=yes
Search -- http://master.php.net/manage/user-notes.php