Please answer this simple SPAM challenge: two minus one?
(Example: nine)

The Note You're Voting On

sep16 at psu dot edu
5 years ago
You can easily parse command line arguments into the $_GET variable by using the parse_str() function.


(implode('&', array_slice($argv, 1)), $_GET);


It behaves exactly like you'd expect with cgi-php.

$ php -f somefile.php a=1 b[]=2 b[]=3

This will set $_GET['a'] to '1' and $_GET['b'] to array('2', '3').

Even better, instead of putting that line in every file, take advantage of PHP's auto_prepend_file directive.  Put that line in its own file and set the auto_prepend_file directive in your cli-specific php.ini like so:

auto_prepend_file = "/etc/php/cli-php5.3/local.prepend.php"

It will be automatically prepended to any PHP file run from the command line.

<< Back to user notes page

To Top