note 108693 added to function.base-convert

From: Date: Thu, 17 May 2012 22:46:55 +0000
Subject: note 108693 added to function.base-convert
Groups: php.notes 
Request: Send a blank email to php-notes+get-188050@lists.php.net to get a copy of this message
If you are building a flat-file system and you do not have the convenience of MySQL's AUTO_INCREMENT feature, you might have a little trouble coming up with incremental identifiers, assuming you rearrange your elements. Rather than storing an integer in a text file and referencing/incrementing it constantly, I use the time() function to generate a unique identifier and base_convert() to make it a little shorter (and hence, more manageable). Obviously, the limitation is creation operation per second. <?php function generate_id($timestamp = null){ if($timestamp == null) $timestamp = time(); return base_convert($timestamp, 10, 36); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 149.169.133.123 ---- Manual Page -- http://www.php.net/manual/en/function.base-convert.php Edit -- https://master.php.net/note/edit/108693 Del: integrated -- https://master.php.net/note/delete/108693/integrated Del: useless -- https://master.php.net/note/delete/108693/useless Del: bad code -- https://master.php.net/note/delete/108693/bad+code Del: spam -- https://master.php.net/note/delete/108693/spam Del: non-english -- https://master.php.net/note/delete/108693/non-english Del: in docs -- https://master.php.net/note/delete/108693/in+docs Del: other reasons-- https://master.php.net/note/delete/108693 Reject -- https://master.php.net/note/reject/108693 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188050) next »