Home >php教程 >PHP源码 >再来个随机字符串

再来个随机字符串

PHP中文网
PHP中文网Original
2016-05-25 17:12:02939browse

php代码

function str_rand($length)//随机字符,参数是长度
{
	if(empty($length))
		return NULL;
	$a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
	$rand_str = '';
	for($i=0;$i<$length;++$i)
	{
		$rand_str .= $a[rand(0,61)];
	}
	return $rand_str;
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn