I have a script that has two options:
// php base64.php -w 80 -f filename
// php base64.php --wrap=80 --file=filename
$options = "f:";
$options .= "w:";
$longopts = array(
"file::",
"wrap::",
);
$opts = getopt($options, $longopts);
if (isset($opts["f"])) {
$filename = file_get_contents($opts["f"]);
$data = base64_encode($filename);
if (isset($opts["w"])) {
$str = wordwrap($data, $opts["w"], PHP_EOL, TRUE);
exit($str . PHP_EOL);
} else {
exit($data . PHP_EOL);
}
} elseif (isset($opts["file"])) {
$filename = file_get_contents($opts["file"]);
$data = base64_encode($filename);
if (isset($opts["wrap"])) {
$str = wordwrap($data, $opts["wrap"], PHP_EOL, TRUE);
exit($str . PHP_EOL);
} else {
exit($data . PHP_EOL);
}
}
However, I can't seem to figure out how to implement the mixing of both short and long options. Any ideas would be welcome 🙂