~~~
/**
* 获取随机字符串
* @param int $randLength 长度
* @param int $addtime 是否加入当前时间戳
* @param int $includenumber 是否包含数字
* @return string
*/
function get_rand_str($randLength=6,$addtime=1,$includenumber=0){
if ($includenumber){
$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQEST123456789';
}else {
$chars='abcdefghijklmnopqrstuvwxyz';
}
$len=strlen($chars);
$randStr='';
for ($i=0;$i<$randLength;$i++){
$randStr.=$chars[rand(0,$len-1)];
}
$tokenvalue=$randStr;
if ($addtime){
$tokenvalue=$randStr.time();
}
return $tokenvalue;
}
~~~
var_dump(get_rand_str());
**输出如下:**
> string(16) "kthaha1461916667"