Several input parameters during php command line running

Source: Internet
Author: User
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! ");




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.