實(shí)現(xiàn)代碼,復(fù)制即用:
<?php
header("Content-type:text/html;charset=utf-8");
function getRandPass($length = 6){
$password = '';
//將你想要的字符添加到下面字符串中,默認(rèn)是數(shù)字0-9和26個(gè)英文字母
$chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$char_len = strlen($chars);
for($i=0;$i<$length;$i++){
$loop = mt_rand(0, ($char_len-1));
//將這個(gè)字符串當(dāng)作一個(gè)數(shù)組,隨機(jī)取出一個(gè)字符,并循環(huán)拼接成你需要的位數(shù)
$password .= $chars[$loop];
}
return $password;
}
echo getRandPass(12); //隨機(jī)生成一個(gè)12位數(shù)的密碼
?>
新聞熱點(diǎn)
疑難解答