Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP命令行脚本-程序使用文本_Php - Fatal编程技术网

PHP命令行脚本-程序使用文本

PHP命令行脚本-程序使用文本,php,Php,我有一个PHP脚本,它接受命令行参数。我希望用户键入不带参数的程序名称: $ ./foo.php 我希望它能输出如下内容: usage: $ ./foo arg1 arg2 where arg1 is something and arg2 is something else 有没有一个标准的方法可以做到这一点 非常感谢:)。您必须使用ARGV从命令行输入中获取这些值。 只需输出它 if (count($_SERVER['argv']) <= 1) { echo 'Usage: $

我有一个PHP脚本,它接受命令行参数。我希望用户键入不带参数的程序名称:

$ ./foo.php
我希望它能输出如下内容:

usage: $ ./foo arg1 arg2 where arg1 is something and arg2 is something else
有没有一个标准的方法可以做到这一点


非常感谢:)。

您必须使用
ARGV
从命令行输入中获取这些值。

只需输出它

if (count($_SERVER['argv']) <= 1) {
  echo 'Usage: $ ' . $_SERVER['argv'][0] . ' arg1 arg2 where arg1 is something and arg2 is something else' . PHP_EOL;
}

if(count($\u SERVER['argv'])虽然这会降低它的可移植性,但您可能希望签出或类似的帮助程序库。