Php randomly generates a combination of numbers and letters. php generates numbers and letters. Php: how to generate a random combination of numbers and letters. php: how to generate a random combination of numbers and letters. Share it with you for your reference. The details are as follows: php randomly generates a combination of numbers and letters.
This example describes how to generate a random combination of numbers and letters in php. Share it with you for your reference. The details are as follows:
Directly run the code:
The code is as follows: 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, a random combination of two letters and numbers is generated.
You only need to call the function and pass parameter 2.
echo getRandomString(2);
You can use a similar method to generate only lower-case letters.
echo chr(mt_rand(65, 90);
Uppercase letters
echo chr(mt_rand(97, 122));
I hope this article will help you with php programming.
Examples in this article describes how to generate a random combination of numbers and letters in php. Share it with you for your reference. Details :...