note 113808 added to function.uniqid

From: Date: Thu, 05 Dec 2013 15:34:22 +0000
Subject: note 113808 added to function.uniqid
Groups: php.notes 
Request: Send a blank email to php-notes+get-197754@lists.php.net to get a copy of this message
If you are storing the value to database it might be more efficient to use more letters than in hexadecimal, for me I decided 0-9a-z is good enough. Notice also that many databases are case insensitive by default so using capitals maybe unwise anyway: <?php function uniqid_base36($more_entropy=false) { $s = uniqid('', $more_entropy); if (!$more_entropy) return base_convert($s, 16, 36); $hex = substr($s, 0, 13); $dec = $s[13] . substr($s, 15); // skip the dot return base_convert($hex, 16, 36) . base_convert($dec, 10, 36); } echo uniqid_base36() . "\n"; // eb98xzzhq7 echo uniqid_base36(true) . "\n"; // eb98xzzhr8dervre ?> String length may vary with this method. ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/function.uniqid.php Edit -- https://master.php.net/note/edit/113808 Del: integrated -- https://master.php.net/note/delete/113808/integrated Del: useless -- https://master.php.net/note/delete/113808/useless Del: bad code -- https://master.php.net/note/delete/113808/bad+code Del: spam -- https://master.php.net/note/delete/113808/spam Del: non-english -- https://master.php.net/note/delete/113808/non-english Del: in docs -- https://master.php.net/note/delete/113808/in+docs Del: other reasons-- https://master.php.net/note/delete/113808 Reject -- https://master.php.net/note/reject/113808 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#197754) next »