如果你需要一个随机字符串,下面这个函数正好帮你,可以自己定义长度
/**
* PHP随机生成指定长度的字符串
*
* @param
* @arrange 512-笔记网: www.jb51.cc
**/
function getCode($length=12) {
//Ascii Code for number,lowercase,uppercase and special characters
$no = range(48,57);
$lo = range(97,122);
$up = range(65,90);
//exclude character I,l,1,O
$eno = array(48,49);
$elo = array(108);
$eup = array(73,79);
$no = array_diff($no,$eno);
$lo = array_diff($lo,$elo);
$up = array_diff($up,$eup);
$chr = array_merge($no,$lo,$up);
for ($i=1;$i<=$length;$i++) {
$code.= chr($chr[rand(0,count($chr)-1)]);
}
return $code;
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/