php随机生成数字字母组合的方法

更新时间:2020-07-21 10:22:37点击:1008 企业动态

php随机生成数字字母组合的方法

本文实例讲述了php随机生成数字字母组合的方法。分享给大家供大家参考。具体如下:

直接上代码:

复制代码 代码如下:
function getRandomString($len, $chars=null)
{
if (is_null($chars)){
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
}
mt_srand(10000000*(double)microtime());
for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
$str .= $chars[mt_rand(0, $lc)];
}
return $str;
}


例如随机生成 2 位 字母和数字组合
只需调用函数 并传参2即可。

?
1
echo getRandomString(2);
< script> (function〇{ var bp = document.createElement( ’script* ); var curProtocol = window.location.protocol.split( )[0]; if (curProtocol = = = ’https’){ bp.src = 'https://zz.bdstatk.com/linksubmit/push.js’ ; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js1 ; } var s = document.getElementsByTagName( Mscriptn )[0]; s.parentNodeJnsertBefore(bp, s); })0; < !-360自动提交代码-> < script> (function〇{ var src = (document.location.protocol == whttp:M )? "http://js.passport.qihucdn.eom/11.0.1 js? d7af82f5d5a7d431d4b53f4d0069f989,,:w https://jspassport.ssl.qhimg.eom/11.0.1.js? d7af82f5d5a7d431d4b53f4d0069f989w ; document.write( ^script src=w * + src + ,u id=" sozz" >* ); })0;