getopt(PHP 4 >= 4.3.0, PHP 5) getopt — Gets options from the command line argument list Описание
array getopt
( string $options
[, array $longopts
] )
Parses options passed to the script. Список параметров
The options parameter may contain the following elements:
Возвращаемые значенияThis function will return an array of option / argument pairs or FALSE on failure.
Список изменений
Примеры
Пример #1 getopt() example
<?phpRunning the above script with php script.php -fvalue -h will output:
array(2) {
["f"]=>
string(5) "value"
["h"]=>
bool(false)
}
Пример #2 getopt() example#2
<?phpRunning the above script with php script.php -f "value for f" -v -a --required value --optional="optional value" --option will output:
array(6) {
["f"]=>
string(11) "value for f"
["v"]=>
bool(false)
["a"]=>
bool(false)
["required"]=>
string(5) "value"
["optional"]=>
string(14) "optional value"
["option"]=>
bool(false)
}
Пример #3 getopt() example#3 Passing multiple options as one
<?phpRunning the above script with php script.php -aaac will output:
array(2) {
["a"]=>
array(3) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
}
["c"]=>
bool(false)
}
|
||||||||||||