score:4

Try this code:

<?php
    $filename = 'info.csv';
    $contents = file($filename);

    foreach($contents as $line) {
       $data = explode(",",$line);
       $val = "[Date.UTC(".substr($data[0],0,4).",".(substr($data[0],4,2)).",".substr($data[0],6,2).",".$data[1].",".$data[2].",".$data[3]."),".$data[4]."],";
    }
?>

score:11

See the fgetcsv and fputcsv PHP functions. It will basically be something like:

if (($handle1 = fopen("input.csv", "r")) !== FALSE) {
    if (($handle2 = fopen("output.csv", "w")) !== FALSE) {
        while (($data = fgetcsv($handle1, 1000, ",")) !== FALSE) {
           // Alter your data
           $data[0] = '...';

           // Write back to CSV format
           fputcsv($handle2, $data);
        }
        fclose($handle2);
    }
    fclose($handle1);
}

Related Query

More Query from same tag