Created
May 3, 2012 14:13
-
-
Save dmdavis/2585915 to your computer and use it in GitHub Desktop.
Random String (PHP)
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 | |
| /** | |
| * Create a random string $l characters in length. | |
| * | |
| * @link http://www.php.net/manual/en/ref.strings.php#84888 | |
| * @param int $l number of characters (default: 10) | |
| * @return string the random string | |
| */ | |
| function random_string($l = 10) { | |
| $c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz0123456789"; | |
| $s = ''; | |
| for(;$l > 0;$l--) | |
| $s .= $c{rand(0,strlen($c))}; | |
| return str_shuffle($s); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment