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

2015年09月05日 1.67k 次阅读 0 条评论

今天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位


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

雨落凋殇

聆听雨落的声音,俯瞰凋零的落叶。伫细雨之中,感雨落之殇。

文章评论(0)