} elseif (is_null($destinationFilename)) { $destinationFilename = $argv[$i]; } else { throw new Exception('Too many parameters!'); } } } } $sot = ini_get('short_open_tag'); if (empty($sot)) { throw new Exception('short_open_tag must be enabled. You can do this in php.ini or in the command-line (eg `php -d short_open_tag=On ...`)'); } if (!is_null($fileList)) { ShortTagsRemover::fromFileList($fileList, true); } elseif (!is_null($sourceFilename)) { ShortTagsRemover::fileToFile($sourceFilename, is_null($destinationFilename) ? $sourceFilename : $destinationFilename, true); } else { $p = isset($argv) && isset($argv[0]) ? $argv[0] : '<programName>'; throw new Exception("Missing parameters. You have the following options:\n\n{$p} <fromFileName> <toFileName>\nTo copy from one file to the other file\n\n{$p} <fileName>\nTo work directly on the file\n\n{$p} --list <fileName>\nTo read the files to work on from a text file. Put one file name in every line to work on the file itseft, the source and destination filenames separated by TAB to copy from source to destination\n\n"); } die(0); } catch (Exception $x) { file_put_contents('php://stderr', $x->getMessage()); die(1); } class ShortTagsRemover { public static function fromFileList($listFilename, $overwrite = false) { if (is_dir($listFilename)) { throw new Exception("'{$listFilename}' is a folder!");
@ini_set('track_errors', true); @ini_set('html_errors', false); @ini_set('display_errors', 'stderr'); @ini_set('display_startup_errors', true); @ini_set('log_errors', false); try { if (empty($argv) || empty($argv[1])) { throw new Exception('Please specify the file name to work on.'); } $sourceFilename = $argv[1]; $destinationFilename = empty($argv[2]) ? $sourceFilename : $argv[2]; $sot = ini_get('short_open_tag'); if (empty($sot)) { throw new Exception('short_open_tag must be enabled. You can do this in php.ini or in the command-line (eg `php -d short_open_tag=On ...`)'); } ShortTagsRemover::fileToFile($sourceFilename, $destinationFilename, true); die(0); } catch (Exception $x) { file_put_contents('php://stderr', $x->getMessage()); die(1); } class ShortTagsRemover { public static function fileToFile($sourceFilename, $destinationFilename, $overwrite = false) { if (is_dir($destinationFilename)) { throw new Exception("'{$destinationFilename}' is a folder!"); } if (!$overwrite && is_file($destinationFilename)) { throw new Exception("'{$destinationFilename}' already exists!"); }