Generate a serial number (compress 12-bit time values into a combination of 7-8 letters and numbers)-PHP source code

Source: Internet
Author: User
Generate the serial number (compress the 12-bit time value into a combination of 7-8 letters and numbers) php code

/*** Generate the serial number ** to compress the 12-digit time value into a combination of 7-8 letters and numbers. The key point is that the user number will never be repeated. * usage: $ serial_no = sofn_generate_serial ('kh '. $ this-> user_login_data ['id']); * Example: QBVF4346 (8-bit, sofn_generate_serial () after 160121054346 (12-bit, date ('ymdhis ') compression ()) * @ param string $ serial_no serial number prefix, for example, 'kh '. $ this-> user_login_data ['id'] * @ return string such as: 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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.