_
_ Handy PHP
_
_
Tutorials, Scripts, Information And Other Resources arrow PHP Functions arrow Singular ID
Sunday, 07 September 2008
_

Refer A Friend using Revolution Money Exchange
Resource Menu
Handy PHP Store
Free Domain Name
PHP Functions
PHP Downloads
PHP Newsfeeds
PHP Tutorials
Webmaster Tools
User Login
TalkPHP
Get friendly help with your PHP problems for free.
www.talkphp.com
The PHP Resource Index
Handy PHP
Free PHP Help!


 
This Section Is Scheduled
For Maintenance

    The format of the PHP Functions section here at Handy PHP needs some attention soon.  Recent changes to the website have brought to light some significant layout problems with this section.  The need for a standard format for all functions has resulted in the problems.  Each function will be reformated, enhanced, archived, and updated as time allows. In the meantime, some screen resolutions may display a distorted version of the website.
Thank you for your visit and patience.

If you encounter any major problems with viewing the functions, please inform us via the forums.
If you are unable to find what you needed here, please let us know what you wanted in the forums so that we may add relevant content in the future.

Singular ID Print E-mail
User Rating: / 0
PoorBest 
PHP Resources - Handy PHP Functions
Written by M. L. Griswold   
Sunday, 03 September 2006
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.



Discuss this article on the forums. (1 posts)
Last Updated ( Tuesday, 05 September 2006 )
 
< Prev   Next >

_
 
_
_
© 2008 Handy PHP