//test.php
1
2echo $a;
//----------------------------
在命令行下用 php.exe test.php即可,
但是变量$a的值怎么给呢??
test.php?a=100例,在网页中可以如此调用,而test.php也可以得到a的值,
在命令行中如何输入呢
---------------------------------------------------------------
I think you can set up environment variables to do that, for example, if you are using Microsoft Windows, try
c:>set a=100
c:>php test.php
or you can add this line to your code:
$a=$argv[1];
then do
c:>php test.php 100
---------------------------------------------------------------
PHP预定义的变量:
'argv'
Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string.
'argc'
Contains the number of command line parameters passed to the script (if run on the command line).
命令:
x:\phpPath\php test.php arg1 arg2 arg3
test.php是第0个参数
test.php:
---------------------------------------------------------------
accorind to this:
http://php.libero.it/manual/en/features.commandline.php
you should do
php a.php "&a=100"
anyone confirm? (I don't have PHP)