Php command line running several input parameters url mode system built-in variable system function getopt
1. url method
$ Param = array (); if ($ argc> 1) {parse_str ($ argv [1], $ param); foreach ($ param as $ k => $ v) {echo "define $ k = $ v \ n"; $ param [$ k] = $ v ;}} print_r ($ param ); // running example php sync_t_search.php "name = sjk & city = bj"
2. built-in system variables
// When multiple or more parameters are input, there are significant limitations. $ argv #0 indicates the name of the currently executed file $ argc # The number of parameters.
3. system function getopt
// 1. personal summary: if only one parameter is passed, (required)/: (optional) you can/2. if multiple parameters are passed, it is optional, we recommend that you use optional parameters whenever possible, and do not enter spaces. // 3. optional parameters: When the identifier exists and there is a value, the subscript will exist. // 4. required parameters: as long as the identifier exists, the subscript will exist (if the value cannot be false)/*** php song. php-h "a B" | php song. php-h "a B" is not affected by spaces (we recommend that you do not add spaces for consistency) array (1) {["h"] => string (3) "a B"} php song. php-h-aarray (1) {["h"] => string (2) "-a"} */var_dump (getopt ('H: :: '); // a required parameter. if there is a space between participants that needs to be enclosed in quotation marks, a space after the option does not affect the value, the values after the parameter will be treated as the parameter value/** php song. php-asongarray (1) {["a"] => string (4) "song"} */var_dump (getopt ('A: h :')); // Optional. the parameter must be followed by the option; otherwise, it cannot be obtained.
4. system function getopt
// Standard output fwrite (STDOUT, "Enter your name:"); echo "\ n"; // standard input $ name = trim (fgets (STDIN )); fwrite (STDOUT, "Hello, $ name! ");