Home > php教程 > PHP源码 > body text

生成序列号(把12位时间数值压缩成7-8位字母+数字组合字符串)

PHP中文网
Release: 2016-05-23 08:39:38
Original
2211 people have browsed it

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;
}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!