Skip to content

Instantly share code, notes, and snippets.

@ivanhoe011
Created November 4, 2014 15:41
Show Gist options
  • Save ivanhoe011/8ead939e49d8f2c9dfe0 to your computer and use it in GitHub Desktop.
Save ivanhoe011/8ead939e49d8f2c9dfe0 to your computer and use it in GitHub Desktop.
Split huge csv vertically
<?php
$split_on_column = 150; // on which column we split
$fp = fopen('big.csv', 'r'); // input
$f1 = fopen('out1.csv', 'w'); // output1
$f2 = fopen('out2.csv', 'w'); // output2
while ($row = fgetcsv($fp)) {
fputcsv($f1, array_slice($row, 0, $split_on_column));
fputcsv($f2, array_slice($row, $split_on_column));
}
fclose($fp);
fclose($f1);
fclose($f2);
// END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment