PHP under CLI (and pass parameters)

Source: Internet
Author: User

There are two ways of passing parameters:

The first use of file operations, stdout as standard output, stdin as standard input

Using Fwrite ($file, $string) as output, use Fgets ($file) as input. This should be considered as inheriting from the C language.

Fwrite (STDOUT,"Hello from Cli,enter your name:"= Trim (fgets (STDIN)); Fwrite ( STDOUT,"Hello, $name! ");

The second one uses two variables $argv array to accept the contents of the parameter, $ARGC the number of statistical parameters.

Can be passed Print_r ($ARGV); echo $ARGC View the results.

The Third Way:

$param _arr = getopt ('a:b:'); #注意是使用a:, B: Accepts parameters. Print_r ($param _arr);
345 -B 12q3-e 3322ffArray    (345    = 12q3)

PHP under CLI (and pass 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.