Created
April 11, 2012 17:44
-
-
Save jt2k/2360854 to your computer and use it in GitHub Desktop.
PHP Golf string inverter
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 | |
$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