当前位置:Gxlcms > PHP教程 > 整型转字符串php生成随机数或者字符串的代码

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

时间:2021-07-01 10:21:17 帮助过:3人阅读

$len表示长度,代码如下:
  1. <br><p><span><u></u></span> 代码如下:</p><p><br>/** <br>* 产生随机字符串 <br>* <br>* 产生一个指定长度的随机字符串,并返回给用户 <br>* <br>* @access public <br>* @param int $len 产生字符串的位数 <br>* @return string <br>*/ <br>function randstr($len=6) { <br>$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ <br>abcdefghijklmnopqrstuvwxyz0123456789-@#~'; <br>// characters to build the password from <br>mt_srand((double)microtime()*1000000*getmypid()); <br>// seed the random number generater (must be done) <br>$password=''; <br>while(strlen($password)<$len) <br>$password.=substr($chars,(mt_rand()%strlen($chars)),1); <br>return $password; <br>}<br></p>
  2. <p>
  3. 以上就介绍了整型转字符串 php生成随机数或者字符串的代码,包括了整型转字符串方面的内容,希望对PHP教程有兴趣的朋友有所帮助。 </p>

人气教程排行