首页 > 代码库 > PHP生成随机字符串
PHP生成随机字符串
<?php class RandChar{ function getRandChar($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; } } $randCharObj = new RandChar(); echo $randCharObj->getRandChar(5); ?>
80个随机字符串生成
<?php class RandChar{ function getRandChar($length){ $str = null; $strPol = "0123456789abcdefghijklmnopqrstuvwxyz"; $max = strlen($strPol)-1; for($i=0;$i<$length;$i++){ $str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数 } return $str; } } $randCharObj = new RandChar(); $word=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5)); $word1=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5)); $word2=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5)); $word3=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5)); $word4=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5)); $word5=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5)); $word6=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5)); $word7=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5)); print_r($word);echo "<br />"; print_r($word1);echo "<br />"; print_r($word2);echo "<br />"; print_r($word3);echo "<br />"; print_r($word4);echo "<br />"; print_r($word5);echo "<br />"; print_r($word6);echo "<br />"; print_r($word7);echo "<br />"; ?>
PHP生成随机字符串
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。