公共函数(common.php)中书写方法:
/**
* 随机生成数字字母(大写)组合
* @param $len 长度
*/
if (!function_exists('getRandomString'))
{
function getRandomString($len, $chars=null)
{
if (is_null($chars)) {
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
}
mt_srand(10000000*(double)microtime());
for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++) {
$str .= $chars[mt_rand(0, $lc)];
}
return $str;
}
}