第一次写文章, 直接进正文吧, 技术不够的地方还请各位大神指出, 刚入门TP不久
//验证码类
public function sjs($sl,$lx)
{
$arr= array(
'set' => "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
);
$cs= array();
$sz= array();
$xzm=array();
$dzm= array();
for ($x= 0 ;$x<=$sl-1 ; $x++){
//全部随机获取
$y= rand (0,61);
$cs[$x]= $arr['set'][$y];
//小写随机获取
$z= rand (10,35);
$xzm[$x]= $arr['set'][$z];
//大写随机获取
$w= rand (36,61);
$dzm[$x]= $arr['set'][$w];
//数字随机获取
$t= rand (0,9);
$sz[$x]= $arr['set'][$t];
}
$arrs= array("数字" => $sz,'小写' => $xzm,'大写' =>$dzm ,'全部' => $cs );
$ax= json_encode ($arrs[$lx],JSON_UNESCAPED_UNICODE);
$str=str_replace('"','',json_encode ($ax));
$str1=str_replace(',','',$str);
$str2=str_replace('[','',$str1);
$str3=str_replace(']','',$str2);
$str4=str_replace('\\','',$str3);
return $str4;
}
//进行调用
public function index(){
$sl= 6; //生成数量
$lx= "全部"; //要生成的类型
$sjs= $this->sjs ($sl,$lx);
//打印输出值
echo $sjs;
}