Generate a random string


/ Published in: PHP
Save to your folder(s)

Useful snippets for php developers.


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.