如何创建自定义随机字母数字 [英] How Do I Create A Customized Random Alphanumerical Digit

查看:103
本文介绍了如何创建自定义随机字母数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在php上创建自定义的随机字母数字。我正在设计收据,我想将其整合到收据上。字母数字应该看起来像TEB00100020到无穷大,应该通过文本字段存储到数据库中。



谢谢

how do i create a customized random Alphanumerical digit on php. am designing a receipt and i want to integrate it on the receipt. the alphanumerical number should look like this TEB00100020 to infinity and should be stored into the database through a textfield.

Thanks

推荐答案

使用mt_rand(min,max)生成值。



对于字母值,在循环中使用它三次,范围跨越1到26(或A至Z的ascii值当量)。在任何一种情况下,都巧妙地从中创建角色值。



然后,使用范围(0,9)循环十次。循环通过你想要的任意数字。



所以 - 看起来应该是这样的:

Use mt_rand(min,max) to generate values.

For alphabetic values, use it in a loop three times with a range that spans 1 through 26 (or ascii value equivalents of A through Z). In either case, cunningly create character values out of them.

Then, loop through it ten times with the range (0, 9). Loop through for as many digits as you wish.

So - it should look something like:


randString =''; //初始化为

为(
randString = ''; // initialize to empty for(


i = 0;


这篇关于如何创建自定义随机字母数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆