经测试代码如下:
/**
* 生成随机密码,可以指定密码长度
*
* @param
* @arrange (512.笔记) jb51.cc
**/
function random_password($length,$characters='abcdefgh1234567890'){
if ($characters == ''){ return ''; }
$chars_length = strlen($characters)-1;
mt_srand((double)microtime()*1000000);
$pwd = '';
while(strlen($pwd) < $length){
$rand_char = mt_rand(0,$chars_length);
$pwd .= $characters[$rand_char];
}
return $pwd;
}
//使用范例
random_password(5,'abcd1234') => returns something like: '2b4d3'
/*** 代码来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528966.html