I have a PHP script that takes arguments as follows: script.php -f "valor"
.
- How do I get PHP to pass this argument via the command line?
I have a PHP script that takes arguments as follows: script.php -f "valor"
.
To get names and argument values from the command line, use $ argv
command line:
php cmd.php -p1 v1 -p2 v2
cmd.php
print_r($argv);
The first item of $argv
is the name of the script. The output of cmd.php will be:
Array
(
[0] => cmd.php
[1] => -p1
[2] => v1
[3] => -p2
[4] => v2
)