/ Published in: PHP
This will generate a random alpha numeric string 20 characters long.
Expand | Embed | Plain Text
Copy this code and paste it in your HTML
<? $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 $str .= $key[$r];//Concatenate the random variable } echo $str;//Show the random string ?>
Comments
Subscribe to comments 