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
|
$file = fopen ( "./shiti.txt" , "r" ); $contentArr = array (); $i =0; //输出文本中所有的行,直到文件结束为止。 while (! feof ( $file )) { $contentArr [ $i ]= fgets ( $file ); //fgets()函数从文件指针中读取一行 $i ++; } fclose( $file ); //$contentArr = array_filter($contentArr); $Shiti = new ShitiModel(); $k = 0; $arr = []; $list = [ 'title' , 'a' , 'b' , 'c' , 'd' , 'answer' , '空' , '' ]; $bArr = []; foreach ( $contentArr as $key => $val ){ if ( $k >=7){ $k = 0; //print_r($arr); $info = $Shiti ->where( 'title' , $arr [ 'title' ])->value( 'title' ); if ( empty ( $info )){ $bArr [] = $arr ; $Shiti ->insert( $arr ); } //$bArr[] = $arr; } if ( $k <6){ $arr [ $list [ $k ]] = trim( $val ); } $k ++; } //$Shiti->insertAll($bArr); exit ; |
出库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$Shiti = new ShitiModel(); $list = $Shiti ->select(); foreach ( $list as $key => $val ){ echo $key +1 . '.' . $val [ 'title' ]; echo '<br>' ; echo $val [ 'a' ]. '<br>' ; echo $val [ 'b' ]. '<br>' ; echo $val [ 'c' ]. '<br>' ; echo $val [ 'd' ]. '<br>' ; echo $val [ 'answer' ]. '<br>' ; echo '<br>' ; } print_r( $list ); exit ; |
多选题
入库
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
|
$file = fopen ( "./shiti.txt" , "r" ); $contentArr = array (); $i =0; //输出文本中所有的行,直到文件结束为止。 while (! feof ( $file )) { $contentArr [ $i ]= fgets ( $file ); //fgets()函数从文件指针中读取一行 $i ++; } fclose( $file ); //$contentArr = array_filter($contentArr); $Shiti = new ShitiModel(); $k = 0; $arr = []; $list = [ 'title' , 'a' , 'b' , 'c' , 'd' , 'e' , 'answer' , '空' , '' ]; $bArr = []; foreach ( $contentArr as $key => $val ){ if ( $k >=8){ $k = 0; //print_r($arr); $info = $Shiti ->where( 'title' , $arr [ 'title' ])->value( 'title' ); if ( empty ( $info )){ $bArr [] = $arr ; $Shiti ->insert( $arr ); } //$bArr[] = $arr; } if ( $k <7){ $arr [ $list [ $k ]] = trim( $val ); } $k ++; } //$Shiti->insertAll($bArr); exit ; |
出库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
$Shiti = new ShitiModel(); $list = $Shiti ->select(); foreach ( $list as $key => $val ){ echo $key +1 . '.' . $val [ 'title' ]; echo '<br>' ; echo $val [ 'a' ]. '<br>' ; echo $val [ 'b' ]. '<br>' ; echo $val [ 'c' ]. '<br>' ; echo $val [ 'd' ]. '<br>' ; echo $val [ 'e' ]. '<br>' ; echo $val [ 'answer' ]. '<br>' ; echo '<br>' ; } print_r( $list ); exit ; |
还没有内容