Skip to content

Instantly share code, notes, and snippets.

@pawiromitchel
Last active February 2, 2017 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawiromitchel/d2fedd6d111b0684c52f427b6dbcd771 to your computer and use it in GitHub Desktop.
Save pawiromitchel/d2fedd6d111b0684c52f427b6dbcd771 to your computer and use it in GitHub Desktop.
PHP - Random string generator
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment