[代码]PHP随机生成字符串

首页 / 源码 / 正文

今天QQ上有朋友要于是就写下了这段代码

    <?php
function code($num =16){
$char =Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');
$i= 0;
while($i < $num){
$rand = mt_rand(0,61);
    $key .=  $char["$rand"];

$i++;
}
return $key;
}
//使用方法
//$a = code(3);    3为随机码个数,可改为任意数字,不填则默认16位


转载请注明雨伤博客及网址

评论区
头像