当前位置:Gxlcms > PHP教程 > PHP生出随机字符串函数

PHP生出随机字符串函数

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

<?php  

/**   
* 产生随机字符串   
*   
* 产生一个指定长度的随机字符串,并返回给用户   
*   
* @access public   
* @param int $len 产生字符串的位数   
* @return string   
*/   
function randStr($len=6) {   
$chars='ABDEFGHJKLMNPQRSTVWXYabdefghijkmnpqrstvwxy23456789#%*'; // 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生出随机字符串函数的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行