网站首页 博客 php生成N位随机字符串
php生成N位随机字符串
 2017-05-09 16:24:56  管理员  218

使用方法:

$randstr = randomkeys(4);

函数定义:

/*产生长度为$length的随机数*/
function randomkeys($length)
{
	$pattern = '1234567890abcdefghijklmnopqrstuvwxyz';
	$key	= '';
	$pmax	= strlen($pattern)-1;
	for($i=0;$i<$length;$i++){
		$key .= $pattern{mt_rand(0,$pmax)};
	}
	return $key;
}


来说两句吧
最新评论