本文实例讲述了php写入数据到CSV文件的方法。分享给大家供大家参考。具体实现方法如下:
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
|
<?php $row = 0; ini_set ( 'max_execution_time' , 300); $cate ; $item ; $value ; $us ; $fp = fopen ( "torah1.csv" , "w" ); if (( $handle = fopen ( "t.csv" , "r" )) !== FALSE) { while (( $data = fgetcsv ( $handle , 1000, "," )) !== FALSE) { $num = count ( $data ); $row ++; for ( $c =0; $c < $num ; $c ++) { if ( $c ==0){ $us = $data [ $c ]; } if ( $c ==1){ $item = explode ( " " , $data [ $c ]); echo "<prE>" ; print_r( $item ); } elseif ( $c ==2){ $value = $data [ $c ]; } elseif ( $c ==3){ $cate1 = $data [ $c ]; } else { } } // end of for loop if ( $row > 1838) { exit ; } fputcsv ( $fp , array ( $us , $item [0], $item [1], $item [2], $item [3])); } //End of While } // End of IF fclose( $handle ); fclose( $fp ); ?> |
希望本文所述对大家的php程序设计有所帮助。