You need to use the $argv array.
Run the following PHP CLI by passing command line arguments to it:
#!/usr/bin/php <?php var_dump($argv); ?>
At startup:
$ chmod u+x a.php $ ./a.php array(1) { [0]=> string(7) "./a.php" } $ ./a.php foo array(2) { [0]=> string(7) "./a.php" [1]=> string(3) "foo" } $
It is clear that $argv[0] contains the name of the script, $argv[1] contains the first command line argument.
the manual contains all the information on how to handle command line arguments.
source share