Skip to content

Instantly share code, notes, and snippets.

@jefferyrdavis
Last active December 19, 2015 17:38
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 jefferyrdavis/5992275 to your computer and use it in GitHub Desktop.
Save jefferyrdavis/5992275 to your computer and use it in GitHub Desktop.
Snippit: PHP: Random String Function
<?php
/* Generates a random string from the charachters listed in $characters and returns the random string.
*/
function genRandomString($length) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%&*()';
$randstring = "";
for ($p = 0; $p < $length; $p++) {
$randstring .= $characters[mt_rand(0, strlen($characters))];
}
return $randstring;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment