NogDog;11062447 wrote:Might I suggest using a "-f" and/or "--file=" argument for the file, in conjunction with the [man]getopt/man function?
I've rewritten the script with your suggestions.
$shortopts = "f:";
$shortopts .= "dbc";
$shortopts .= "ibc"; // not implemented yet
$shortopts .= "w:"; // not implemented yet
$longopts = array(
"file:", // not implemented yet
"decode", // not implemented yet
"ignore-garbage", // not implemented yet
"wrap::", // not implemented yet
"help",
"version",
);
$options = getopt($shortopts, $longopts);
if (isset($options["f"])) {
exit(base64_encode(file_get_contents($options[f])) . PHP_EOL);
}
if (isset($options["d"])) {
exit(base64_decode(file_get_contents("php://stdin")) . PHP_EOL);
}
if (empty($argv[1])) {
exit(base64_encode(file_get_contents("php://stdin")). PHP_EOL);
}
if (isset($options["help"])) {
exit(file_get_contents("base64_help.txt") . PHP_EOL);
}
if (isset($options["version"])) {
exit("base64 version 0.6.1" . PHP_EOL);
}
You've set me in the right direction, thank you.