概述
echo coding(6);
function coding($num){
$str_arr = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');
$rand_s = array_rand($str_arr,$num);
$code_s = '';
if(is_array($rand_s)){
foreach($rand_s as $v){
$code_s .= $str_arr[$v];
}
return $code_s;
}else{
return $str_arr['rand_s'];
}
}
/**
* 生成一个随机的数字英文混合编码
* @param int $num 生成几位数字
* @param int $method 可定义随机码组合方式
* return string
*/
function coding2($num,$method = 6){
$lower_arr = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$upper_arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$num_arr = array('0','1','2','3','4','5','6','7','8','9');
switch($method){
case 1: $str_arr = $num_arr;//纯数字
case 2: $str_arr = $lower_arr;//纯字母小写
case 3: $str_arr = $upper_arr;//纯字母大写
case 4: $str_arr = array_merge($lower_arr,$num_arr);//字母(小写)数字
case 5: $str_arr = array_merge($upper_arr,$num_arr);//字母(大写)数字
case 6: $str_arr = array_merge($lower_arr,$upper_arr,$num_arr);//字母(小大写)数字
case 7: $str_arr = array_merge($lower_arr,$upper_arr);//字母(小大写)
}
$rand_s = array_rand($str_arr,$num);
$code_s = '';
if(is_array($rand_s)){
foreach($rand_s as $v){
$code_s .= $str_arr[$v];
}
return $code_s;
}else{
return $str_arr['rand_s'];
}
}
?>
本文出自 “php工程师的博客” 博客,谢绝转载!
最后
以上就是傲娇小甜瓜为你收集整理的php生成64位随机码,php生成一个可选位数的随机码的全部内容,希望文章能够帮你解决php生成64位随机码,php生成一个可选位数的随机码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复