PHP - Windows中的命令行参数

7 php parameters command-line

我正在尝试从Windows XP下的命令行运行PHP.

这是有效的,除了我无法为我的PHP脚本提供参数这一事实.

我的测试用例:

echo "param = ".$param."\n";  
var_dump($argv);  
Run Code Online (Sandbox Code Playgroud)

我想称之为:

php.exe -f test.php -- param=test

但我从来没有让脚本接受我的参数.

我从上面的脚本得到的结果

`PHP注意:未定义的变量:第2行的C:\ test.php中的param

param = ''
array(2) {
  [0]=> string(8) "test.php"
  [1]=> string(10) "param=test"
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用PHP 5.2.6.这是PHP5中的错误吗?

参数传递在在线帮助中 处理.Note: If you need to pass arguments to your scripts you need to pass -- as the first argument when using the -f switch. 这似乎在PHP4下工作,但不在PHP5下.在PHP4下,我可以使用可以在服务器上运行的相同脚本,而无需在命令行上进行更改.这对于本地调试很方便,例如将输出保存在要研究的文件中.

Ada*_*ght 7

为什么你有任何期望将param设置为该值?您负责从$ argv数组中以您想要的方式解析命令行.