手机
当前位置:查字典教程网 >编程开发 >php教程 >php生成随机数或者字符串的代码
php生成随机数或者字符串的代码
摘要:$len表示长度,代码如下:复制代码代码如下:/***产生随机字符串**产生一个指定长度的随机字符串,并返回给用户**@accesspubl...

$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快速查找数据库中恶意代码的方法

php转换颜色为其反色的方法

php将字符串随机分割成不同长度数组的方法

php编写批量生成不重复的卡号密码代码

php简单操作mysql数据库的类

php计算到指定日期还有多少天的方法

我的论坛源代码(十)

php判断文本文档字符编码

php对数组内元素进行随机调换的方法

在 PHP 中使用随机数的三个步骤

精品推荐
分类导航