PHP uses getopt () to parse cli parameters, getoptcli

Source: Internet
Author: User

PHP uses getopt () to parse cli parameters, getoptcli

The getopt () in the PHP manual is described as follows:

/**

* Gets options from the command line argument list

* @ Link http://php.net/manual/en/function.getopt.php

* @ Param string $ options Each character in this string will be used as option characters and

* Matched against options passed to the script starting with a single

* Hyphen (-).

* For example, an option string "x" recognizes

* Option-x.

* Only a-z, A-Z and 0-9 are allowed.

* @ Param array $ longopts [optional] An array of options. Each element in this array will be used as option

* Strings and matched against options passed to the script starting

* Two hyphens (--).

* For example, an longopts element "opt" recognizes

* Option -- opt.

* Prior to PHP5.3.0 this parameter was only available on few systems

* @ Param int $ optind If the optind parameter is present, then the index where argument parsing stopped will be written to this variable.

* @ Return array This function will return an array of option/argument pairs or false on

* Failure.

* @ Since 4.3.0

* @ Since 5.0

*/

Function getopt ($ options, array $ longopts = null, & $ optind = null ){}

 

$ Options: String type. Each character is used as an option character. The option that matches the input script starts with a single hyphen. For example, an option string "x" identifies an option-x. Only a-z, A-Z, and 0-9 are allowed.

The character parameters can be followed:

$ Longopts: Array type. Each element in this array is used as an option string and matches the options passed into the script with two hyphens. For example, the long option element "opt" identifies an option -- opt.

$ OptionsAnd$ LongoptsThe format is almost the same. The only difference is that$ LongoptsIt must be an array of options (each element is an option), while$ OptionsA string is required (each character is an option ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.