Skip to content

Instantly share code, notes, and snippets.

@nhalstead
Created August 29, 2018 02:33
Show Gist options
  • Save nhalstead/b65f6d3971fbf0cfe1dae96964655023 to your computer and use it in GitHub Desktop.
Save nhalstead/b65f6d3971fbf0cfe1dae96964655023 to your computer and use it in GitHub Desktop.
Random String Gen
<?php
/**
* Random String Gen
*
* @link https://stackoverflow.com/a/4356295/5779200
* @param int Length of the String
* @return string The Random String
*/
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