In the previous we have introduced the PHP random number generation method, but did not specifically describe the generated PHP random number is what, then we will introduce the PHP random generation of digital letter combination method, an example of PHP generated random numbers and random letters related techniques and usage, very practical value, Need friends can refer to the next!
A method of generating PHP random numbers from digital letters
function getrandomstring ($len, $chars =null) { if (Is_null ($chars)) { $chars = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "; } Mt_srand (10000000* (double) microtime ()); for ($i = 0, $str = ", $LC = strlen ($chars)-1; $i < $len; $i + +) { $str. = $chars [Mt_rand (0, $LC)]; } return $STR;}
For example randomly generated 2-bit letters and number combinations
Just call the function and pass parameter 2.
Echo getrandomstring (2);
If you just generate lowercase letters you can use a similar method
Echo Chr (Mt_rand (65, 90);
Capital
Echo Chr (Mt_rand (97, 122));
Summarize:
See here believe a lot of small partners on the generation of PHP random number and further understanding, can have alphanumeric composition, as well as the letter of the case, this article can do a good job, hope to your work has some help!
Related recommendations:
Five ways to generate PHP random numbers without repetition
A method for generating random numbers in PHP
PHP random number red envelope random generation algorithm PHP version