Skip to content

Instantly share code, notes, and snippets.

@jt2k
Created April 11, 2012 17:44
Show Gist options
  • Save jt2k/2360854 to your computer and use it in GitHub Desktop.
Save jt2k/2360854 to your computer and use it in GitHub Desktop.
PHP Golf string inverter
<?php
$strings = array(
"\n"
);
if (!isset($argv[1]))
{
die("Please specify an input file\n");
}
$file = $argv[1];
$newfile = preg_replace('/\.php/', '.inv.php', $file);
$input = @file_get_contents($file);
if (!$input)
{
die("Could not open input file\n");
}
$output = $input;
foreach ($strings as $string)
{
$find = "\"{$string}\"";
$replace = "~" . ~$string;
$output = str_replace($find, $replace, $output);
$find = "'{$string}'";
$replace = "~" . ~$string;
$output = str_replace($find, $replace, $output);
}
file_put_contents($newfile, $output);
exit("Output saved to $newfile\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment