PHP Command Line Arguments and Options

后端 未结 2 1616
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 10:20

I am writing a small command line application in php.

What is the correct way to handle command line arguments and options?

There seems to be the argv arra

2条回答
  •  猫巷女王i
    2020-12-19 10:53

    You can retrieve the "raw" arguments using $argv. See also: http://www.php.net/manual/de/reserved.variables.argv.php

    Example: php file.php a b c

    $argv will contain "file.php", "a", "b" and "c".

    Use getopts to get the parameters "parsed", PHP will do the dirty job for you. So it's probably the best way to go in your case as you want to pass the parameters with --options. Have a close look at http://www.php.net/manual/de/function.getopt.php It describes the function well.

提交回复
热议问题