Generate Random String


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

I didn't make this, I just found it online and found it really useful for generating unique IDs for stuff.

Have fun using this.


Copy this code and paste it in your HTML
  1. function genRandomString($length) {
  2. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  3. $string = '';
  4. for ($p = 0; $p < $length; $p++) {
  5. $string .= $characters[mt_rand(0, strlen($characters))];
  6. }
  7. return $string;
  8. }
  9.  
  10. //////////////////////////////////////
  11. // Example : //
  12. // //
  13. // echo genRandomString(rand(3,7)); //
  14. // //
  15. // Could Print Out: Ac1dF //
  16.  
  17. //////////////////////////////////////

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.