php modify csv file

Solutions on MaxInterview for php modify csv file by the best coders in the world

showing results for - "php modify csv file"
Hope
17 Apr 2019
1$myfile = 'sample_csv.csv';
2
3$fin = fopen($myfile, 'r');
4$data = array();
5
6   /***********
7   * header row
8   */
9$data[] = fgetcsv($fin, 1000);
10  /***********
11   * data rows
12   */
13while ($line = fgetcsv($fin, 1000)) {
14   echo join(', ', $line).'<br>';
15   for($i = 4, $k = count($line); $i < $k; $i++) {
16    if ($line[$i] < 1000) {
17	    $line[$i] = 10000;
18    }
19   }
20   $data[] = $line;
21}
22
23fclose($fin);
24   /******************
25   * reopen file and
26   * write array to file
27   */
28$fout = fopen($myfile, 'w');
29foreach ($data as $line) {
30   fputcsv($fout, $line);
31}
32fclose($fout);