We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

Abe on 01/30/08


Tagged

random String


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

oli964


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.