Generate a random string, which can be expanded by yourself $type can be: upper (only generates uppercase letters), lower (only generates lowercase letters), number (only generates numbers) $len is the length, defining the length of the string
- /***************************
- * Generate random strings and can be expanded by yourself
- * $type can be: upper (only uppercase letters are generated), lower (only lowercase letters are generated), number (only numbers are generated)
- * $len is the length, defining the string length
- ************************ ****/
- function _random($type,$len)
- {
- $new = '';
- $string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; //Random number pool
- if($type= ='upper')
- {
- for($i = 0;$i<$len;$i++)
- {
- $new .= $string[mt_rand(36,61)];
- }
- return $new;
- }
- if($type == 'lower')
- {
- for($i = 0;$i<$len;$i++)
- {
- $new .= $string[mt_rand(10,35)];
- }
- return $new;
- }
- if($type == 'number')
- {
- for($i = 0;$i<$len;$i++)
- {
- $new .= $string[mt_rand( 0,9)];
- }
- return $new;
- }
- }
Copy code
|