PHP生成自定义长度随机字符串实例
- php语言
- 关注:2.63W次
导语:PHP生成自定义长度随机字符串函数,你懂吗?下面的`是本站小编为大家搜集的PHP生成自定义长度随机字符串的函数资料,供大家参考。
php随机生成字符串可以自己定义自己所需要的长度,在实际应用开发中,经常遇到。
代码如下:
//随机生成字符串
function random($length) {
srand(date("s"));
$possible_charactors = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$string = "";
while(strlen($string)<$length) {
$string .= substr($possible_charactors,(rand()%(strlen($possible_charactors))),1);
}
return($string);
}
- 文章版权属于文章作者所有,转载请注明 https://xuezhezhai.com/jsj/php/r2gq56.html