2010/06/18

php command line 的參數(Arguments)取用

PHP 命令列使用參數的取用

程式範例:

$ vim argu.php

#!/usr/bin/php -q

<?php

echo "Test Arguments:\n";

echo $_SERVER["argc"]."\n";

echo $_SERVER["argv"][0]."\n";

echo $_SERVER["argv"][1]."\n";

echo $_SERVER["argv"][2]."\n";

echo $_SERVER["argv"][3]."\n";

echo $_SERVER["argv"][4]."\n";

?>



執行過程:

$ php argu.php a b c d

Test Arguments:

5

argu.php

a

b

c

d



參考:
http://www.php.net/manual/en/features.commandline.options.php
http://www.php-cli.com/php-cli-tutorial.shtml#args

沒有留言: