您的位置 首页 php

php生成随机字符串公共类分享

生成随机 字符串 公共类分享;

通过改变$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);

文章来源:智云一二三科技

文章标题:php生成随机字符串公共类分享

文章地址:https://www.zhihuclub.com/151521.shtml

关于作者: 智云科技

热门文章

网站地图