Passing command-line arguments into PHP

Say you have a PHP script and you want to pass command-line arguments into the script, e.g. calling the script like this:

php script.php datafile.txt 10 100

PHP stores all command-line arguments in an array:
$argv 0 => “script.php”
$argv 1 => “datafile.txt”
$argv 2 => 10
$argv 3 => 100

Then you can process the arguments:

if (!isset($argv1) {
print “Usage: php script.php [ ]\n”;

$filename = $argv1;

See the article Using PHP from the command line for details.