1 && substr($arg, 0, 1) == '-') { // For each character for ($c = 1; $c < strlen($arg); $c++) { $ch = $arg{$c}; $ok = false; foreach ($known_opts as $opt) { $add_args = 0; while (substr($opt, -1) == '=') { $add_args++; $opt = substr($opt, 0, -1); } if ($ch == $opt) { $this_opt = array($opt); while ($add_args--) { $i++; if (!isset($argv[$i])) die("Too few parameters for option '-$ch'\n"); $this_opt[] = $argv[$i]; } $opts[] = $this_opt; $ok = true; break; } } if (!$ok) { die("Unrecognised option '-$ch'\n"); } } } // Non-options else { $args[] = $arg; } } // Find if an option is set // Optionally checks a second name and combines with OR // function is_option_set($name, $name2 = null) { global $opts; foreach ($opts as $opt) { if ($opt[0] == $name) { return true; } if ($name2 && $opt[0] == $name2) { return true; } } return false; } // Get the first option parameter for a given option name // Only finds the first occurance of an option // Optionally checks a second name // function get_option_value($name, $name2 = null) { global $opts; foreach ($opts as $opt) { if ($opt[0] == $name) { return $opt[1]; } if ($name2 && $opt[0] == $name2) { return $opt[1]; } } } // Get the first option parameter for a given option name // Finds all occurances of an option // Optionally checks a second name // function get_all_option_values($name, $name2 = null) { global $opts; $ret = array(); foreach ($opts as $opt) { if ($opt[0] == $name) { $ret[] = $opt[1]; } if ($name2 && $opt[0] == $name2) { $ret[] = $opt[1]; } } return $ret; } // Get all option parameters for a given option name // Only finds the first occurance of an option // Optionally checks a second name // function get_option_all_values($name, $name2 = null) { global $opts; foreach ($opts as $opt) { if ($opt[0] == $name) { return array_slice($opt, 1); } if ($name2 && $opt[0] == $name2) { return array_slice($opt, 1); } } } // Get the n-th argument // function get_argument($n) { global $args; if (isset($args[$n])) return $args[$n]; return ''; } ?>