I wrote a short function to handle this situation - if the command line arguments are present and the $ _REQUEST array is empty (i.e. when you run the script from the command line and not through the web interface), it looks for command line arguments in key = value pairs ,
Argv2Request($argv); print_r($_REQUEST); function Argv2Request($argv) { /* When $_REQUEST is empty and $argv is defined, interpret $argv[1]...$argv[n] as key => value pairs and load them into the $_REQUEST array This allows the php command line to subsitute for GET/POST values, eg PHP .php animal=fish color=red number=1 has_car=true has_star=false */ if ($argv !== NULL && sizeof($_REQUEST) == 0) { $argv0 = array_shift($argv); // first arg is different and is not needed foreach ($argv as $pair) { list ($k, $v) = split("=", $pair); $_REQUEST[$k] = $v; } } }
An example is given in a comment on a function presented in a comment on a function:
PHP .php animal=fish color=red number=1 has_car=true has_star=false
which gives an output:
Array ( [animal] => fish [color] => red [number] => 1 [has_car] => true [has_star] => false )
source share