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; }
相关推荐
amberom 2020-08-03
有梦就能实现 2020-06-10
poplpsure 2020-05-27
fujuan000 2020-04-30
Crazyshark 2019-06-25
知足者常乐 2019-09-02
有梦就能实现 2018-05-20
Crazyshark 2014-07-24
drise 2013-11-25
ahxxx 2019-07-01
spinachcqb 2019-06-28
技术渣 2016-10-07
会写code的凳子哥 2016-09-23
Phplayers 2019-06-28
wangdoudou0 2015-07-07
cxymds 2019-06-27
spinachcqb 2019-06-27