Created
December 1, 2009 15:13
-
-
Save dsingleton/246349 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 | |
$aOutput = array(); | |
$aLines = explode("\n", file_get_contents($argv[1])); | |
$aKeys = explode("\t", array_shift($aLines)); | |
foreach($aLines as $line) { | |
if (!trim($line)) { | |
break; | |
} | |
$aValues = explode("\t", trim($line)); | |
if (count($aKeys) > count($aValues) && count($aValues) > 6) { | |
// Fewer keys... | |
$aKeys = array_slice($aKeys, 0, count($aValues)); | |
} | |
if (count($aValues) < count($aKeys)) { | |
// Or blank values... | |
$aValues = array_pad($aValues, count($aKeys), ''); | |
} | |
$item = var_export(array_combine($aKeys, $aValues), true); | |
// mung mung mung, get an array var export on to 1 line, improve readability | |
$item = str_replace("\n", "", $item); | |
$item = str_replace(" ", " ", $item); | |
$item = str_replace("array ( ", "array(", $item); | |
$item = str_replace(",)", ")", $item); | |
$aOutput[] = $item; | |
} | |
echo "array(\n\t" . join($aOutput, ",\n\t") . "\n);"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment