1k views
Generate random string with PHP
There are a lot of ways to achieve random strings generation, but this is a pretty decent and simple one:
PHP
- //
- // Generates a random key with a fixed lenght, passed as parameter.
- // The string may contain any character
- public static function generateRandomKey($length)
- {
- $randstr = "";
- for($i=0; $i<$length; $i++)
- {
- if($randnum < 10)
- {
- }
- else if($randnum < 36)
- {
- }
- else
- {
- }
- }
- return $randstr;
- }
Submitted by miguelSantirso over 2 years ago — last modified less than a minute ago