cxdy
PHP Developer
- Jun 8, 2014
- 100
- 27
I made a random string generator in PHP.
You can use this for things like passwords, file names, etc. Anything you can think of.
To change the length of the string, edit the 10 in $length on line one.
Enjoy.
The function:
Then, if you ever want to call it,
You can use this for things like passwords, file names, etc. Anything you can think of.
To change the length of the string, edit the 10 in $length on line one.
Enjoy.
The function:
PHP:
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
PHP:
echo generateRandomString();