If you want to implement PHP command-line read parameters, the CLI can get the number and value of the arguments from $_server[' argc ' and $_server[' argv ']. Let's create a file with the name testargs.php and the script code as follows:
- #! C:phpphp.exe–q
- < ? PHP
- UNIX and Linux platforms should be
#!/usr/local/bin/php–q
- echo "Test get parameter: n";
- echo $_server["ARGC"]. " n ";
- Displays the parameter values passed in, starting at index 1
- echo $_server["argv"][1]. " n ";
- echo $_server["argv"][2]. " n ";
- echo $_server["argv"][3]. " n ";
- echo $_server["argv"][4]. " n ";
- ?>
Enter the following code on the command line:
C:usersjohn>testargs.php always to being best
Test Get Parameters:
4
Always
To
Be
Best
Because we entered a string of words, the script parameters are separated by a space. As a result, PHP counts it as 4 parameters, as described below.
$_server[the "ARGC"] array returns the number of an integral type, representing a total of several parameters entered after the carriage return from the command line.
The result from reading the parameter sample from the PHP command line shows that to access the parameter values that have been passed in, you need to start at index 1. Because the script itself's file already occupies index 0, that is $_server["argv"][0].
http://www.bkjia.com/PHPjc/446037.html www.bkjia.com true http://www.bkjia.com/PHPjc/446037.html techarticle if you want to implement PHP command-line read parameters, the CLI can get the number and value of the arguments from $_server[' argc ' and $_server[' argv ']. We create a file, named testargs.php, Script generation ...