Bri*_*ter 2 php command-line-interface
我试图在CLI中运行时将参数传递给PHP脚本。我一直在使用以下代码来做到这一点...
// Set argument variables
// A is the filetype
// B is the filename and directory
$arguments = getopt("a:b:");
// If we're importing pies...
if($arguments['a'] == 'pies') {
echo 'File Conversion and Import of PIES Data Beginning Now...' . "\n\n";
}
Run Code Online (Sandbox Code Playgroud)
命令看起来像这样...:
php fileimport.php -a pies -b /filepath/filename.xml
Run Code Online (Sandbox Code Playgroud)
我已经看到参数以其他方式传递(对于其他脚本),例如...
php fileimport --type=pies --path=filepath/filename.xml
Run Code Online (Sandbox Code Playgroud)
我个人比较喜欢这种方法,但是我不知道如何编写PHP脚本来收集这些参数,更不用说期待它们了。我敢肯定这很简单,如果我错过了明显的事情,我感到抱歉,但是我希望在这里找到一些指导。
谢谢!
如PHP文档中所述:
$shortopts = "";
$longopts = array(
"type:",
"path:",
);
// Get command line arguments
$options = getopt($shortopts, $longopts);
echo 'Input Options: ', PHP_EOL;
var_dump($options);
Run Code Online (Sandbox Code Playgroud)