Programatically edit a CSV file
Here’s an example of adding a leading zero to columns 2 and 3 of the CSV file:
$input = fopen('numbers.csv','r');
$output = fopen('numbers_touched.csv','w');
while($csv_line = fgetcsv($input,1024)) {
$line = array();
foreach ($csv_line as $k => $field){
if ($k == 2 || $k == 3) {
$field = '0' . $field;
}
$line[] = $field;
}
fputcsv($output,$line);
}
fclose($input);
fclose($output);
No comments yet
