Last active
December 19, 2015 17:38
-
-
Save jefferyrdavis/5992275 to your computer and use it in GitHub Desktop.
Snippit: PHP: Random String Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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