21,886
社区成员
发帖
与我相关
我的任务
分享
function getRandStr($len){
$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZzbcdefghijklmnopqrstuvwxyz";
$output = "";
for ($i=0; $i<$len; $i++){
$output .= $str{mt_rand(0, 52)};
}
return $output;
}
稍微修改了下,谢谢楼上两位
结贴
<?php
function getRandStr($len){
$chars = array("0", "1", "2","3", "4", "5", "6", "7", "8", "9"); //换成a-z,A-Z 52种
$charsLen = count($chars) - 1;
shuffle($chars);
$output = "";
for ($i=0; $i<$len; $i++){
$output .= $chars[mt_rand(0, $charsLen)];
}
return $output;
}
?>