PHP Php随机字符串生成器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Php随机字符串生成器相关的知识,希望对你有一定的参考价值。

<?

$l='a';					//Set the starting letter
for($i=0;$i<26;$i++){	//Cycle through all of the letters of the alphabet a-z
	$key[$i]=$l;		//Load the array with lowercase variables at position $i
	$l++;				//Increment the letter
}
for($x=0;$x<5;$x++){	//Cycle through this five times. The more you cycle through this loop the more likely a number will appear.
	for($n=0;$n<10;$n++){	//Cycle through the numbers 0-9
		$key[$i]=$n;	//Load the array with number variables at position $i
		$i++;			//Increment the array key
	}
}
$u='A';					//Set the starting letter
for($c=0;$c<26;$c++){	//Cycle through all of the letters of the alphabet A-Z
	$key[$i]=$u;		//Load the array with uppercase variables
	$i++;				//Increment the array key
	$u++;				//Increment the letter
}

$i--;	//Subtract the last incrementation of $i because it's not indexed

$str='';
for($strlength=0;$strlength<20;$strlength++){	//Generate the random string 20 characters long
	//$r = rand(0,$i);	//Generate a random number from the available $i interger
	$r = rand()&$i;		//Generate a random number from the available $i interger using bitwise
	$str .= $key[$r];	//Concatenate the random variable
}

echo $str;	//Show the random string
?>

以上是关于PHP Php随机字符串生成器的主要内容,如果未能解决你的问题,请参考以下文章

php [PHP]生成随机字符串

随机字符串生成器 PHP [重复]

PHP生成随机字符串

PHP 生成随机字符串与唯一字符串

PHP生成随机字符串与唯一字符串

PHP 随机字符串生成器