- /**
- * @param string $len length
- * @param string $type strings type
- * 0 Letters 1 numbers other mixes
- * @param string $addChars extra characters
- * @return String
- */
- function leipi_rand_string ($len =6,$type =",$addChars =") {
- $str =";
- switch ($type) {
- Case 0:
- $chars =' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz '. $addChars;
- Break ;
- Case 1:
- $chars = str_repeat (' 0123456789 ', 3);
- Break ;
- Case 2:
- $chars =' abcdefghijklmnopqrstuvwxyz '. $addChars;
- Break ;
- Case 3:
- $chars =' abcdefghijklmnopqrstuvwxyz '. $addChars;
- Break ;
- Case 4:
- $chars = "Some random Chinese can be entered here. " $addChars;
- Break ;
- Default:
- //default is to remove the easily confusing characters Ooll and number 01, to add please use the Addchars parameter
- $chars =' ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789 '. $addChars;
- Break ;
- }
- if ($len >10) {//bit too long repeating string a certain number of times
- $chars = $type ==1? str_repeat ($chars,$len): str_repeat ($chars, 5);
- }
- if ($type!=4) {
- $chars = str_shuffle ($chars);
- $str = substr ($chars, 0,$len);
- }else{
- //Chinese random word
- For ($i =0; $i <$len; $i + +) {
- $str. = Msubstr ($chars, Floor (Mt_rand (0,mb_strlen ($chars,' Utf-8 ')-1)), 1);
- }
- }
- return $str;
- }
PHP Random string password generation