Created
January 24, 2014 23:04
-
-
Save tunix/8608648 to your computer and use it in GitHub Desktop.
This file contains 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 | |
$row = 0; | |
$head = array(); | |
$result = array(); | |
$columnCount = 0; | |
$input = @$argv[1]; | |
$output = @$argv[2]; | |
if (empty($input) OR empty($output)) { | |
die("Either input or output is empty!"); | |
} | |
if (($handle = fopen($input, "r")) !== FALSE) { | |
while (($data = fgetcsv($handle, 1000000, "|")) !== FALSE) { | |
$num = count($data); | |
if ($row == 0) { | |
$head = $data; | |
$columnCount = $num; | |
$row++; | |
continue; | |
} | |
if ($num != $columnCount) { | |
echo 'Kolon sayisi uymuyor (num:' . $num . ', columnCount: ' . $columnCount . ')'; | |
die(print_r($data, true)); | |
} | |
$row++; | |
$obj = new StdClass(); | |
for ($c=0; $c < $num; $c++) { | |
$h = $head[$c]; | |
$obj->$h = $data[$c]; | |
} | |
$result[] = $obj; | |
} | |
fclose($handle); | |
} | |
file_put_contents($output, json_encode($result, JSON_PRETTY_PRINT)); | |
echo "$output olusturuldu\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment