1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
function getRandStr($length, $multiplex = true, $string = 'abcdefghijkmnpqrstuvwxyz0123456789ABCDEFGHIGKLMNPQRSTUVWXYZ') { if($length < 0) { return false; } $strlen = strlen($string); if (!$multiplex) { if ($length > $strlen) { return false; } $shuffled = str_shuffle($string); $rand_str = substr($shuffled, 0, $length); } else { $rand_str = ''; $max = $strlen-1; for ($i = 0; $i < $length; $i++) { $rand_str .= $string[mt_rand(0, $max)]; } } return $rand_str; }
|