Skip to content

Instantly share code, notes, and snippets.

@dsingleton
Created December 1, 2009 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dsingleton/246349 to your computer and use it in GitHub Desktop.
Save dsingleton/246349 to your computer and use it in GitHub Desktop.
<?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