Ec (2); function: Obtain random string parameters: 1, (int) $ length32 # random character length 2, (int) $ mode0 # random character type, 0 is a combination of uppercase and lowercase English letters and numbers, 1 is a number, 2 is a lowercase wood, 3 is an uppercase letter, 4 is a lowercase letter, and 5 is an uppercase letter and number, 6 is returned for lowercase letters and numbers: the obtained string & lt ;? PhpclassactiveCodeObj {functiongetCode ($ script ec (2); script
Purpose: obtain a random string.
Parameters:
1. (int) $ length = 32 # random character length
2. (int) $ mode = 0 # random character type. 0 indicates uppercase and lowercase English letters and numbers, 1 indicates numbers, 2 indicates lowercase wood, 3 indicates uppercase letters, and 4 indicates uppercase and lowercase letters, 5 is an uppercase letter and number, and 6 is a lowercase letter and number.
Return: The obtained string.
Class activeCodeObj
{
Function getCode ($ length = 32, $ mode = 0)
{
Switch ($ mode ){
Case '1 ':
$ Str = '000000 ';
Break;
Case '2 ':
$ Str = 'abcdefghijklmnopqrstuvwxy ';
Break;
Case '3 ':
$ Str = 'abcdefghijklmnopqrstuvwxy ';
Break;
Case '4 ':
$ Str = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy ';
Break;
Case '5 ':
$ Str = 'abcdefghijklmnopqrstuvwxyz1234567890 ';
Break;
Case '6 ':
$ Str = 'abcdefghijklmnopqrstuvwxyz1234567890 ';
Break;
Default:
$ Str = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234567890 ';
Break;
}
$ Result = '';
$ L = strlen ($ str );
For ($ I = 0; $ I <$ length; $ I ){
$ Num = rand (0, $ l );
$ Result. = $ str [$ num];
}
Return $ result;
}
}
?>
Instructions for use:
1. Save the code in the above box as random. php
2. introduce random. php on the required page
3. Use the previously defined class
$ Code = new activeCodeObj;
$ Length = 32;
$ Mode = 0;
$ Str = $ code-> getCode ($ length, $ mode );
Echo $ str;
?>