Created
June 5, 2014 09:26
-
-
Save loopool/efcb852bc06112456ebe to your computer and use it in GitHub Desktop.
PHP generate random string
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 | |
//Normal way | |
function generateRandomString($length = 10) { | |
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
$randomString = ''; | |
for ($i = 0; $i < $length; $i++) { | |
$randomString .= $characters[rand(0, strlen($characters) - 1)]; | |
} | |
return $randomString; | |
} | |
echo generateRandomString(); | |
?> |
Author
loopool
commented
Jun 5, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment