note 108693 deleted from function.base-convert by googleguy
| From: | googleguy@php.net | Date: | Tue, 09 Jul 2013 11:51:16 +0000 |
| Subject: | note 108693 deleted from function.base-convert by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195543@lists.php.net to get a copy of this message | ||
Note Submitter: wyattstorch42 at gmail dot com
----
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);
}
?>