Generate Random String


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

If you don’t need human readable string, then use this function instead, which will create a random string you can use for user id’s etc.


Copy this code and paste it in your HTML
  1. /*************
  2. *@l - length of random string
  3. */
  4. function generate_rand($l){
  5. $c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  6. srand((double)microtime()*1000000);
  7. for($i=0; $i<$l; $i++) {
  8. $rand.= $c[rand()%strlen($c)];
  9. }
  10. return $rand;
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.