Skip to content

Instantly share code, notes, and snippets.

@Wol
Created June 4, 2018 09:44
Show Gist options
  • Save Wol/40cd5e79cd9e9235779f9950a6a55ff3 to your computer and use it in GitHub Desktop.
Save Wol/40cd5e79cd9e9235779f9950a6a55ff3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
function stdin_stream()
{
while ($line = fgets(STDIN)) {
yield $line;
}
}
$columnsizes = [];
foreach (stdin_stream() as $line) {
// do something with the contents coming in from STDIN
$parts = explode("\t", trim($line));
foreach ($parts as $column => $part) {
$slen = strlen($part);
if (!isset($columnsizes[$column])) {
$columnsizes[$column] = 8;
}
$columnsizes[$column] = max(1 + ceil($slen / 8) * 8, $columnsizes[$column]);
echo $part . str_repeat(" ", $columnsizes[$column] - $slen);
}
echo "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment