'1234567890', 'letter' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'string' => 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789', 'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' ); if (!isset($config[$type])) $type = 'string'; $string = $config[$type]; $code = ''; $strlen = strlen($string) - 1; for ($i = 0; $i < $length; $i++) { $code .= $string{mt_rand(0, $strlen)}; } if (!empty($convert)) { $code = ($convert > 0) ? strtoupper($code) : strtolower($code); } return $code; } /** * 生成唯一不重复 32 位字符串 */ public static function uniqueString() { return md5(uniqid(microtime(true), true)); } /** * 返回两位数字母 * @param $in_array * @return string */ public static function getChr($in_array) { $return_sta = chr(rand(65, 90)) . chr(rand(65, 90)); if (!count($in_array) || !in_array($return_sta, $in_array)) { return $return_sta; } $str = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'L', 'M', 'N']; for ($i = 0; $i < strlen((string)$str); $i++) { for ($j = 0; $j < strlen((string)$str); $j++) { if (!in_array($str[$i] . $str[$j], $in_array)) { return $str[$i] . $str[$j]; continue; } } } } }