Method of accepting parameters in CLI command-line mode in PHP

Source: Internet
Author: User
Tags php cli

There are several ways to accept parameters in the PHP CLI (command line mode):

(1) using $ARGV to accept parameters

<?php

The code is as follows Copy Code
Variables are available only when REGISTER_ARGC_ARGV is open.
Print_r ($ARGC); Gets the number of arguments under the CLI, with a minimum value of 1
Print_r ($ARGV); An array of arguments passed to the script under the CLI, the first parameter is always the filename of the current script, so $argv [0] is the script file name.


Results:


Several methods for accepting parameters under PHP CLI (2) using the getopt () function to get the parameters

<?php

The code is as follows Copy Code
Get-a-b-C parameter
$args = getopt (' a:b:c: ');
Print_r ($args);


Execution results:


Using getopt to get CLI parameters

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.