PHP生成随机码

浏览:154 发布日期:2019/12/16 分类:功能实现 关键字: -
-
/**
* 生成随机码
*/
function rand_code($length, $type) {
$rand_factor = array("0123456789",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"~@#$%^&*(){}[]|");

if (($type < 0 && $type != -1) || $type > 4) {
$type = 0;
}

if (0 == $type) {
array_pop($rand_factor);
$rand_src = implode("", $rand_factor);
} else if (-1 == $type) {
$rand_src = implode("", $rand_factor);
} else {
$rand_src = $rand_factor[$type];
}

$code = '';
$count = strlen($rand_src) - 1;
for ($i = 0; $i < $length; $i++) {
$code .= $rand_src[rand(0, $count)];
}

return $code;
}
评论( 相关
后面还有条评论,点击查看>>
广东快乐十分