What this article shares with you is a very practical code that is often used in projects and can generate unique card numbers in batches There are two methods for card number passwords. Friends in need can refer to them.
When I was free, I wanted to improve my skills in array manipulation in PHP, so I wrote the following small code, which can randomly generate arrays corresponding to card numbers and passwords, and automatically remove repetitions. There is no idea, just pure in vain.
?
|
<🎜>function MakeCard()<🎜>
<🎜>{<🎜>
<🎜>set_time_limit(0);<🎜>
<🎜> <🎜>
<🎜>//Processing buffer<🎜>
<🎜>ob_end_clean();<🎜>
<🎜>ob_implicit_flush(true);<🎜>
<🎜>echo str_pad(" ", 256);<🎜>
<🎜> <🎜>
<🎜>if(intval($_POST['num']>0)) $num=intval($_POST['num']); //Quantity
if(intval($_POST['point']>0)) $point=intval($_POST['point']); //Points
if(intval($_POST['batch']>0)) $batch=intval($_POST['batch']); //Batch number
if(($_POST['ym']!="")) $ym=$_POST['ym']; //Year and month of release
else $ym=date('ym');
if($num==0) return;
$num=$num*100; //The number of cards, that is, the number of records
echo " Start ".date("H:i:s")." ";
for($i=1;$i<=$num;$i )<🎜>
<🎜>{<🎜>
<🎜>$sn=sprintf(" s%s s",$batch,$ym,$i);<🎜>
<🎜>$seek=mt_rand(0,9999).mt_rand(0,9999).mt_rand(0,9999); //12 digits<🎜>
<🎜>$start=mt_rand(0,20);<🎜>
<🎜>$str=strtoupper(substr(md5($seek),$start,12));<🎜>
<🎜>$str=str_replace("O",chr(mt_rand(65,78)),$str);<🎜>
<🎜>$str=str_replace("0",chr(mt_rand(65,78)),$str);<🎜>
<🎜>$row=array('sn'=>$sn,'password'=>$str,'created'=>time(),'point'=>$point);
//Check for plagiarism
//Add the code to insert data here.
print_r($row);
}
echo " end ".date("H:i:s")."";
printf(" |
Method 2:
?
2 3 11 12
13
14
15
16
17
18
19
20
21
22
23
|
<🎜>$numLen=16;<🎜> <🎜>$pwdLen=10;<🎜> <🎜>$c=100;//Generate 100 sets of card number passwords<🎜> <🎜>$sNumArr=range(0,9);<🎜> <🎜>$sPwdArr=array_merge($sNumArr,range('A','Z'));<🎜> <🎜> <🎜> <🎜>$cards=array();<🎜> <🎜>for($x=0;$x< $c;$x ){<🎜> <🎜>$tempNumStr=array();<🎜> <🎜>for($i=0;$i< $numLen;$i ){<🎜> <🎜>$tempNumStr[]=array_rand($sNumArr);<🎜> <🎜>}<🎜> <🎜>$tempPwdStr=array();<🎜> <🎜>for($i=0;$i< $pwdLen;$i ){<🎜> <🎜>$tempPwdStr[]=$sPwdArr[array_rand($sPwdArr)];<🎜> <🎜>}<🎜> <🎜>$cards[$x]['no']=implode('',$tempNumStr);<🎜> <🎜>$cards[$x]['pwd']=implode('',$tempPwdStr);<🎜> <🎜>}<🎜> <🎜>array_unique($cards);<🎜> <🎜>print_r($cards);<🎜> <🎜>?> |