php生成随机数或者字符串的代码
时间:2021-06-20 08:47:57|栏目:PHP代码|点击: 次
$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;
}
复制代码 代码如下:
/**
* 产生随机字符串
*
* 产生一个指定长度的随机字符串,并返回给用户
*
* @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;
}
上一篇:PHP中使用Session配合Javascript实现文件上传进度条功能
栏 目:PHP代码
下一篇:PHP实现登录搜狐广告获取广告联盟数据的方法【附demo源码】
本文标题:php生成随机数或者字符串的代码
本文地址:http://www.codeinn.net/misctech/144826.html






