Hi,
how do i pass arguments to a php-script when it is run from the commandline?
e.g. php.exe -q mytest.php arg1=foo arg2=bar
is this possible? i tried it like the example, but i won't work. any solutions?
Thanks
Servet (Win2k running PHP 4.06)
hi Servet,
you should read the following article: http://www.phpbuilder.com/columns/darrell20000319.php3 it contains the info you are looking for.
from commandline: php.exe -q mytest.php foo bar
in file mytest.php <?php
$scriptname = $argv[0]; $arg1 = $argv[1]; $arg2 = $argv[2];
echo $arg1 ."\n". $arg2 ."\n";
?>
this will print: foo bar
never do something else before you read the array $argv, and remember the first value of the array is always the filename.
greetings