|
getoptGets options from the command line argument list Beschreibung
array getopt
( string
$options
[, array $longopts
[, int &$optind
]] )Parses options passed to the script. Parameter-Liste
The
Rückgabewerte
This function will return an array of option / argument pairs, Im Fehlerfall wird
Changelog
Beispiele
Beispiel #1 getopt example: The basics
<?phpshell> php example.php -fvalue -h Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
array(2) {
["f"]=>
string(5) "value"
["h"]=>
bool(false)
}
Beispiel #2 getopt example: Introducing long options
<?phpshell> php example.php -f "value for f" -v -a --required value --optional="optional value" --option Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
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)
}
Beispiel #3 getopt example: Passing multiple options as one
<?phpshell> php example.php -aaac Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
array(2) {
["a"]=>
array(3) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
}
["c"]=>
bool(false)
}
Beispiel #4 getopt example: Using
<?phpshell> php example.php -a 1 -b 2 -- test Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
array(1) {
[0]=>
string(4) "test"
}
|