2010-11-11 138 views
1

在我的Ruby代碼,我使用反引號(`)執行一個PHP腳本,如:傳遞參數

result = `php #{RAILS_ROOT}/lib/php/test.php` 

如何傳遞參數在這個PHP腳本?

我如何獲取(php)腳本中的參數?

謝謝!

回答

2

在PHP手冊中查看Using PHP from the command line

This page有一個完整的例子:

# This will not execute the given code but will show the PHP usage 
$ php -r 'var_dump($argv);' -h 
Usage: php [options] [-f] <file> [args...] 
[...] 

# This will pass the '-h' argument to your script and prevent PHP from showing it's usage 
$ php -r 'var_dump($argv);' -- -h 
array(2) { 
    [0]=> 
    string(1) "-" 
    [1]=> 
    string(2) "-h" 
}