Created
August 9, 2012 20:55
-
-
Save CrowderSoup/3307964 to your computer and use it in GitHub Desktop.
PHP Random String Generator
This file contains 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 | |
function get_rand_str($length) | |
{ | |
$chars = array_merge(range('a','z'), range('A','Z'), array('!','@','#','$','%','&','*')); | |
$length = intval($length) > 0 ? intval($length) : 16; | |
$max = count($chars) - 1; | |
$str = ""; | |
while($length--) { | |
shuffle($chars); | |
$rand = mt_rand(0, $max); | |
$str .= $chars[$rand]; | |
} | |
return $str; | |
} | |
echo (get_rand_str($_GET['len'])); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment