php代码
/** * 生成序列号 * 把12位时间数值压缩成7-8位字母+数字组合字符串,重点是加上用户编号后将永不重复哈 * 用法:$serial_no = sofn_generate_serial('KH' . $this->user_login_data['id']); * 示例:160121054346(12位,date('ymdhis'))压缩后QBVF4346(8位,sofn_generate_serial()) * @param string $serial_no 序号前缀,如:'KH' . $this->user_login_data['id'] * @return string 如:QBVF295 * @since VER:1.0; DATE:2016-1-21; AUTHOR:SoChishun; EMAIL:14507247@qq.com; DESC:Added. */ function sofn_generate_serial($serial_no='') { $time = date('y-m-d-H-i-s'); $atime = explode('-', $time); foreach ($atime as $stime) { $itime = $stime * 1; if ($itime < 26) { // 65(A)-90(Z) $serial_no.=chr(65 + $itime); continue; } // 48(0)-57(9) if ($itime >= 48 && $itime <= 57) { $serial_no.=chr($stime); continue; } $serial_no.=$stime; } return $serial_no; }