生成随机 字符串 公共类分享;
通过改变$strPol变量原始数据内容,可生成包含不通内容的数据;
代码:
<?php
/**
* @name RandString
* @desc 随机字符串
* @author
*/class RandString {
public static function getRandString($length) {
$str = null;
$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen ($strPol) - 1;
for ($i = 0; $i < $length; $i++) {
$str .= $strPol[rand(0, $max)]; //rand($min,$max)生成介于min和max两个数之间的一个随机整数
}
return $str;
}
}
调用方式:
echo ‘生成长度5的字符串:’.RandString::getRandString(5);