/** * 生成任意长度随机验证码(不足位补0) * @param int $length // 长度 * @param int $padType // 补0方式 0.STR_PAD_LEFT 1.STR_PAD_RIGHT 2.STR_PAD_BOTH * @return int|string */ function generateCode($length = 6, $padType = 2) { $length = is_numeric($length) ? (int) abs($length) : 6; $max = pow(10, $length) - 1; return str_pad(mt_rand(0, $max), $length, "0", $padType); }
php 生成任意长度的随机码,验证码
版权归原作者所有,如有侵权请告知。达维营-前端网 » php 生成任意长度的随机码,验证码
相关推荐
- PHP将时间戳格式化为几分钟前、几小时前、几天前
- Flashfxp文件传输到服务器后部分文件代码报错
- php7.4报错:Trying to access array offset on value of type null
- Thinkphp切换php版本报错:implode(): Passing glue string after array is deprecated. Swap the parameters
- php报错:Parse error: syntax error, unexpected end of file;Parse error: syntax error, unexpected end of file “]”
- getimagesize(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed - php end,array_shift,array_pop Only variables can be passed by reference
- laravel常用插件库