当前位置: 移动技术网 > IT编程>开发语言>PHP > php生成随机数或者字符串的代码

php生成随机数或者字符串的代码

2019年05月10日  | 移动技术网IT编程  | 我要评论
$len表示长度,代码如下:
复制代码 代码如下:

/**
* 产生随机字符串
*
* 产生一个指定长度的随机字符串,并返回给用户
*
* @access public
* @param int $len 产生字符串的位数
* @return string
*/
function randstr($len=6) {
$chars='abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz0123456789-@#~';
// characters to build the password from
mt_srand((double)microtime()*1000000*getmypid());
// seed the random number generater (must be done)
$password='';
while(strlen($password)<$len)
$password.=substr($chars,(mt_rand()%strlen($chars)),1);
return $password;
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网