O'Reilly logo

Programming PHP, 3rd Edition by Peter MacIntyre, Kevin Tatroe, Rasmus Lerdorf

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

getopt

Synopsis

array getopt(string short_options[, array long_options])

Parses the command-line arguments list used to invoke the current script and returns an associative array of optional name/value pairs. The short_options and long_options parameters define the command-line arguments to parse.

The short_options parameter is a single string, with each character representing a single argument passed into the script via a single hyphen. For example, the short options string "ar" matches the command-line arguments -a -r. Any character followed by a single colon : requires a value to match, while any character followed by two colons :: optionally includes a value to match. For example, "a:r::x" would match the command-line arguments -aTest -r -x but not -a -r -x.

The long_options parameter is an array of strings, with each element representing a single argument passed into the script via a double hyphen. For example, the element "verbose" matches the command-line argument --verbose. All parameters specified in the long_options parameter optionally match values in the command line separated from the option name with an equals sign. For example, "verbose" will match both --verbose and --verbose=1.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required