How several incoming parameters are run by PHP command line mode

Source: Internet
Author: User
Url method

<strong> $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); Run the sample php sync_t_search.php "NAME=SJK&CITY=BJ" </strong>

System built-in variables

<strong>//There are significant limitations when multiple or multiple parameters are passed in $argv #0为当前执行的文件名 $argc #参数个数 </strong>

system function getopt

<STRONG>//1, Personal Summary: If only one parameter,: (Required)/:: (optional) can be//2, if the number of parameters to distinguish between optional required, it is recommended to use optional parameters and the following values do not pass the space//3, optional parameters: identifiers exist and have values, Subscript does not exist//4, required parameter: As long as the identifier exists, the subscript will exist (if not the value is False)/** * php song.php-h "a B" | | PHP song.php-h "A B" is not affected by whitespace (it is recommended to keep no spaces) 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 the participation in quotation marks, the option is followed by a blank space will not affect the value, will be the value of his back as the value of the parameter /**php Song.php-asongarray (1) {  ["a"]=>  string (4) "Song"} */var_dump (Getopt (' a::h: '));//Optional parameters, Parameter must be immediately following the option or not get </strong>

4. System function getopt

<strong>//standard output fwrite (STDOUT, "Enter your Name:"); echo "\ n";//Standard input $name = Trim (fgets (STDIN)); Fwrite (STDOUT, " Hello, $name! "); </strong>
  • 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.