php随机生成验证码,php随机生成数字,php随机生成数字加字母!
2022-07-28 15:09:43
166
{{single.collect_count}}
<?php/* * 方法类 * */class functions{/** * PHP随机生成验证码函数 * * @param array * @returnmixed */function randCode($params = []){$num = $params['num'] ?? 4; //验证码个数$isLetter = $params['isLetter'] ? $params['isLetter'] : 1; //1是纯数字 2是字母和数字的组合if($isLetter==1){for($i=1;$i<=$num;$i++){$codeMin.=0;$codeMax.=9;}return rand($codeMin,$codeMax);}if($isLetter==2){//如果想调整权重,自己可以根据需求修改$codeArr这个一位数组$codeArr = ['1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','e','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0'];$codeKeys = array_rand($codeArr,$num);shuffle($codeKeys);foreach ($codeKeys as $codeValue){$codeStr .= $codeArr[$codeValue];}return $codeStr;}}}//测试生成验证码方法$re = (new functions())->randCode(['num'=> 6, //需要的个数'isLetter' => 2, //1是纯数字 2是数字加字符串]);print_r($re);

测试结果如下
在这里插入图片描述

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}