note 42221 deleted from function.uniqid by aidan

From: Date: Sun, 07 Nov 2004 11:50:53 +0000
Subject: note 42221 deleted from function.uniqid by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80220@lists.php.net to get a copy of this message
Note Submitter: kasimir-k.fi ---- 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; }

« previous php.notes (#80220) next »