Created
April 29, 2016 09:46
-
-
Save rskuipers/a24142c6265b306b2e591697d70c1abc to your computer and use it in GitHub Desktop.
Sometimes you don't have the access to do a nice COPY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$psqlDelimiter = '|'; | |
$outputDelimiter = ';'; | |
$file = new SplFileObject(__DIR__ . '/psql.csv'); | |
$output = new SplFileObject(__DIR__ . '/output.csv', 'w'); | |
$i = 0; | |
while (!$file->eof()) { | |
if ($i === 1) { | |
$file->fgetcsv($psqlDelimiter); | |
$i++; | |
continue; | |
} | |
$row = array_map('trim', $file->fgetcsv($psqlDelimiter)); | |
$output->fputcsv($row, $outputDelimiter); | |
$i++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment