note 42221 added to function.uniqid
| From: | kasimir-k dot fi at rn2 dot php dot net | Date: | Sat, 08 May 2004 15:30:40 +0000 |
| Subject: | note 42221 added to function.uniqid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69344@lists.php.net to get a copy of this message | ||
This function returns unique 12 characters long 36 base string (chars 0-9A-Z) - this is often nicer
than the 32 characters that md5 gives.
/*
36 ^ 12 = 4738381338321616896
which is 19 chars long
hence adding of random 0 - 3 if $str is shorter than 19 chars
*/
function uniq_12_str()
{
$str = uniqid('',FALSE);
$str = base_convert($str, 16, 10)
$str = strrev($str);
while(strlen($str) < 19)
{
$str = rand(0,3) . $str;
}
$str = base_convert($str, 10, 36);
$str = str_pad($str, 12 ,'0' ,STR_PAD_LEFT)
$str = strtoupper($str);
return $str;
}
----
Manual Page -- http://www.php.net/manual/en/function.uniqid.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42221
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42221&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42221&report=yes
Search -- http://master.php.net/manage/user-notes.php