闲的蛋疼的时候,顺便加强下自己对PHP中数组操纵的一些技巧,就写了下面的一段小代码,可以随机生成卡号密码对应的数组,并且自动去重复,思路没有,纯粹瞎掰。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<?php header( 'Content-Type:text/html; charset=utf-8' );
function MakeCard()
{
set_time_limit(0);
//处理缓冲区
ob_end_clean();
ob_implicit_flush(true);
echo str_pad ( " " , 256);
if ( intval ( $_POST [ 'num' ]>0)) $num = intval ( $_POST [ 'num' ]); //数量
if ( intval ( $_POST [ 'point' ]>0)) $point = intval ( $_POST [ 'point' ]); //点数
if ( intval ( $_POST [ 'batch' ]>0)) $batch = intval ( $_POST [ 'batch' ]); //批号
if (( $_POST [ 'ym' ]!= "" )) $ym = $_POST [ 'ym' ]; //发行年月
else $ym = date ( 'ym' );
if ( $num ==0) return ;
$num = $num *100; //卡的张数,即记录数
echo "<p>开始 " . date ( "H:i:s" ). " " ;
for ( $i =1; $i <= $num ; $i ++)
{
$sn =sprintf( "%02s%s%06s" , $batch , $ym , $i );
$seek =mt_rand(0,9999).mt_rand(0,9999).mt_rand(0,9999); //12位
$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 );
//查重
//在这里加插入数据的代码.
print_r( $row );
}
echo " 结束 " . date ( "H:i:s" ). "" ;
printf( "<br>成功生成:%s万个 %s点 的密码</p>" , $num /1e4, $point );
return $num ;
} //函数结束
$_POST [ 'num' ]=1;
$_POST [ 'point' ]=10;
$_POST [ 'batch' ]=10;
$_POST [ 'ym' ]= '1405' ;
echo MakeCard(); ?>
|
方法二:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<?php
$numLen =16;
$pwdLen =10;
$c =100; //生成100组卡号密码
$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 );
?>
|
以上所述就是本文的全部内容了,希望大家能够喜欢。