Execute the $ argv and $ argc configuration methods in the php script through the command line, argvargc

Source: Internet
Author: User

Execute the $ argv and $ argc configuration methods in the php script through the command line, argvargc

In actual work, you may encounter the need to execute a php script in the nginx command line. Of course, you can configure a conf file for Internet access.

Use

php index.php

You can execute this index. php script, but how to pass the parameter? $ Argv and $ aegc will be used. You do not need to enable any settings and use them directly in the script, similar to $ _ POST and $ _ GET. In http values ..

Insert the following dish in index. php?

<?phpecho $argv[0];     echo "\n";var_dump($argv[1]);    echo "\n";var_dump(intval($argv[2]));  echo "\n";echo $argv[3];     echo "\n";echo $argc;

Then use

php index.php 1 10 100

Display

Index. php // $ argv [0]: The result is tested. This shows the relative path of the script relative to the execution location (where do you enter the php index. php. The index is displayed here. php relative to the location of your current directory) string (1) "1" // $ argv [1] shows that the first parameter is converted into a string int (10) // $ argv [2] shows the second parameter 100 // $ argv [3] shows the relative path of the second parameter 4 // $ argv parameter + the parameter you passed

For convenience of memorizing this variable$ Avgv is an argument vector, and $ avgc is an argument count

Details:

Http://php.net/manual/zh/reserved.variables.argv.php#93532

Summary

The above section describes how to execute $ argv and $ argc in the php script through a command line. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.