Two methods for passing parameters through the command line to php _ PHP Tutorial

Source: Internet
Author: User
The command line can be used to pass parameters to php. # $ Argvor $ argc $ argv contains an array of parameters passed to the current script when running under the command line. $ Argv [0] indicates the script file name. $ Argc: when running in the command line, it is passed to ##$ argv or $ argc.
$ Argv contains an array of parameters passed to the current script when running under the command line. $ Argv [0] indicates the script file name.
$ Argc contains the number of parameters passed to the current script when running in the command line. The script file name is always passed to the current script as a parameter, so the minimum value of $ argc is 1.
The two variables are only available when register_argc_argv is enabled.

Note: $ argv and $ argc must declare global variables in class methods or functions.

 
  


# Getopt
Array getopt (string $ options [, array $ longopts])
Options each character in the string is treated as an option character. the options that match the input script start with a single hyphen. For example, an option string "x" identifies an option-x. Only a-z, A-Z, and 0-9 are allowed. Array of longopts options. 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.

Options may contain the following elements:
1. separate characters (value not accepted)
2. the character that follows the colon (this option requires a value)
3. followed by two colon characters (optional value of this option)
The value of the option is the first parameter after the string. It does not mind whether there is a space before the value.


Return value:
This function returns an option/parameter pair, and FALSE if it fails.


Note:
The option value does not accept space ("") as the separator.
The formats of options and longopts are almost the same. The only difference is that longopts needs to be an array of options (each element is an option ), options requires a string (each character is an option ).
The parsing of options will end with the first non-option found, and any subsequent items will be discarded.

Arguments or $ argc $ argv contains an array of parameters passed to the current script when running in the command line. $ Argv [0] indicates the script file name. $ Argc contains the information that is passed to the command line when running under the command line...

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.