Skip to content

Instantly share code, notes, and snippets.

@ninsuo
Created May 10, 2019 15:27
Show Gist options
  • Save ninsuo/d41ba41c9aa24ce06298225df4f83858 to your computer and use it in GitHub Desktop.
Save ninsuo/d41ba41c9aa24ce06298225df4f83858 to your computer and use it in GitHub Desktop.
Takes each line in stdin, and wrap it with a template
<?php
if (!isset($argv[1])) {
die(sprintf('You forgot to give a template: %s "<prefix> %%s <suffix>"%s', $argv[0], "\n"));
}
$template = $argv[1];
$raw = file_get_contents('php://stdin');
$lines = explode(PHP_EOL, $raw);
foreach ($lines as $line) {
echo str_replace('%s', $line, $template), PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment