Basically, to write cli program with PHP we just use $argv ($argv is enough, $argc - if necessary). $argv contains an array of all the arguments passed to the script when running from the command line.
for($i = 1; $i < $argc; ++$i) {
echo $argv[$i]. "\n";
}
In addition, if we 'd expect to get arguments passed like option1=value1
$ php cli_program.php opt1=val1 opt2=val2
we can parse the command line arguments into $_GET by using parse_str() function.
No comments:
Post a Comment