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

php教程评论127 views阅读模式

$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;
}

以上就介绍了整型转字符串 php生成随机数或者字符串的代码,包括了整型转字符串方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

企鹅博客
  • 本文由 发表于 2020年9月14日 12:05:49
  • 转载请务必保留本文链接:https://www.qieseo.com/321346.html

发表评论