Posted By

Abe on 01/30/08


Tagged

random String


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

oli964
vali29


Random String


 / Published in: PHP
 

URL: http://snippets.dzone.com/posts/show/3123

  1. <?php
  2. function randomStr($len = 16) {
  3. $base = 'ABCDEFGHKLMNOPQRSTWXYZabcdefghjkmnpqrstwxyz123456789';
  4. $max = strlen($base)-1;
  5. $activatecode = '';
  6. mt_srand((double)microtime()*1000000);
  7. while (strlen($activatecode) < $len+1)
  8. $activatecode .= $base{mt_rand(0,$max)};
  9. return $activatecode;
  10. }
  11.  
  12. echo randomStr(8);
  13. ?>

Report this snippet  

You need to login to post a comment.