PHP CLI with parameters

October 21, 2008

For a current project, I needed a (PHP) CLI script that had to accept a certain parameter list. Using CLI, you can do:

php /path/to/script/script.php arg1 arg2 arg3

I retrieve the parameters in the script by using the $_SERVER[‘argv’] array:

$param1 = $_SERVER[‘argv’][0];

$param2 = $_SERVER[‘argv’][1];

I kinda feel dirty using the $_SERVER[‘argv’] variable. Any decent method to do this?

One Response to “PHP CLI with parameters”

  1. cakyus Says:

    getopt ?


Leave a comment