php获取指定数量随机字符串的方法
本文实例讲述了php获取指定数量随机字符串的方法,分享给大家供大家参考,具体如下:
- functiongetARandLetter($number= 1) {
- if($number== 0)
- returnFALSE;//去除0
- $number=$number< 0 ? -$number:$number;//如果小于零取正值
- $letterArr=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');
- $returnStr=''
- for($i= 0;$i<$number;$i++) {
- $returnStr.=$letterArr[rand ( 0, 51 )];
- }
- return$returnStr;
- }
- echogetARandLetter(8);