- 代码:
/*
@desc:生成随机字符串
@param $len 要生成的字符串长度
@return str 生成的字符串
*/
function randstr($len){
$pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ,./<>?;#:@~[]{}-_=+)(*&^%FCKpd0pound;”!';
$strlen = mb_strlen($pattern) - 1;
$str = "";
for($i = 0;$i < $len;$i++){
$str .= $pattern[mt_rand(0,$strlen)];
}
return $str;
}
- 测试:
$ret = randstr(10);
var_dump($ret);
- 输出:
string(10) "t8{OQ;,Sz["
|