2010-11-11 106 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" 
}