PHP随机生成字母加数字的字符串

PHP随机生成字母加数字的字符串

function GetRandStr($length) {
        $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $len = strlen($str) - 1;
        $randstr = '';
        for ($i = 0; $i < $length; $i++) {
            $num = mt_rand(0, $len);
            $randstr .= $str[$num];
        }
        return $randstr;
    }
$a = GetRandStr(8);
var_dump(GetRandStr)

 

你可能感兴趣的:(PHP)