php生成随机长度字符串

php生成随机长度字符串

只要穿长度的参数就行了,具体代码如下:

	public function getRandStr($len) //len字符串长度
	{
	    $chars = 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','0','1','2','3','4','5','6','7','8','9');//你想填写的随机数
	    $charsLen = count($chars) - 1;
	    shuffle($chars);
	    $output = '';
	    for ($i = 0; $i < $len; $i++) {
	        $output .= $chars[mt_rand(0, $charsLen)];
	    }
	    return $output;
	}

猜你喜欢

转载自blog.csdn.net/hzthis/article/details/84143232
今日推荐