当前位置:网站首页>随机生成数字字母(大写)组合

随机生成数字字母(大写)组合

2022-06-10 09:52:00 u011042325

公共函数(common.php)中书写方法:

/**
 * 随机生成数字字母(大写)组合
 * @param  $len  长度  
 */
if (!function_exists('getRandomString'))
{
    function getRandomString($len, $chars=null)
    {
        if (is_null($chars)) {
            $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        }
        mt_srand(10000000*(double)microtime());
        for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++) {
            $str .= $chars[mt_rand(0, $lc)];
        }
        return $str;
    }
}


原网站

版权声明
本文为[u011042325]所创,转载请带上原文链接,感谢
https://blog.csdn.net/u011042325/article/details/80332361

随机推荐