PHP生成自定义长度随机字符串的函数分享_php实例
程序员文章站
2022-04-19 21:16:47
...
php随机生成字符串可以自己定义自己所需要的长度,在实际应用开发中,经常遇到。
//随机生成字符串
function random($length) {
srand(date("s"));
$possible_charactors = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$string = "";
while(strlen($string) $string .= substr($possible_charactors,(rand()%(strlen($possible_charactors))),1);
}
return($string);
}
复制代码 代码如下:
//随机生成字符串
function random($length) {
srand(date("s"));
$possible_charactors = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$string = "";
while(strlen($string) $string .= substr($possible_charactors,(rand()%(strlen($possible_charactors))),1);
}
return($string);
}