Posted By

jamepaul on 08/27/10


Tagged

php randomstring


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

daubu
googooster


Generate a random string


 / Published in: PHP
 

URL: http://webdeveloperplus.com/php/21-really-useful-handy-php-code-snippets/

Useful snippets for php developers.

  1. <?php
  2. /*************
  3.  *@l - length of random string
  4.  */
  5. function generate_rand($l){
  6. $c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  7. srand((double)microtime()*1000000);
  8. for($i=0; $i<$l; $i++) {
  9. $rand.= $c[rand()%strlen($c)];
  10. }
  11. return $rand;
  12. }
  13. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: tuuul on August 21, 2011

Exactly what I needed. Thanks!

You need to login to post a comment.