|
Written by Handy PHP Administrator
|
|
Sunday, 03 September 2006 15:13 |
| Description: | | | string singular_id(int number[, string prefix[, string suffix[, bool case]]]) | | | | | | | This is a modification of the uniqid function. The uniqid function allows for only 13 charaters plus a prefix. This function was designed to make a larger id than 13 characters without having to go to 32 characters with MD5 or 40 characters with sha1. This will allow unique id's to be generated with anywhere from 13 to 127 characters plus a prefix and a suffix. Additionaly, this function has the option to select upper or lower case output. | | | | | | Function: | | | function singular_id($size=16, $prefix='', $suffix='', $case=0){ // Function written by Marcus L. Griswold (vujsa) // Can be found at http://www.handyphp.com // Do not remove this header! $prefix_size = count(count_chars($prefix, 1)); $suffix_size = count(count_chars($suffix, 1)); $added_chars = $size - 13 - $prefix_size - $suffix_size; if($added_chars < 0){ $added_chars = 0; } $id = $prefix . uniqid(substr(md5(rand(0,99999)),rand(0,29), $added_chars)) . $suffix; if($case){ $id = strtoupper($id); } return $id; } | | | | | | Usage: | | | echo singular_id(16,'pre','suf',1); | | | | | Result: | | | PRE44FD26FB3DC62SUF | | | | | Notes: | | | There is a 127 character limit for the core of the id generated. This does not include the number of characters in either the prefix or the suffix. The output of the function is lower case by default. |
{mos_sb_discuss:3}
|
|
Last Updated on Tuesday, 05 September 2006 08:24 |