PHP » PYTHON |
login |
register |
about
|
import sys, getopt result = getopt(sys.argv, options) result = getopt(sys.argv, options, longopts) also see the "optparse" module, which is more powerful getopt(PHP 4 >= 4.3.0, PHP 5) getopt — Gets options from the command line argument list Description
array getopt
( string $options
[, array $longopts
] )
Parses options passed to the script. Parameters
The options parameter may contain the following elements:
Option values are the first argument after the string. It does not matter if a value has leading white space or not.
Return ValuesThis function will return an array of option / argument pairs or FALSE on failure. Changelog
Examples
Example #1 getopt() Example
<?phpRunning the above script with php script.php -fvalue -h will output:
array(2) {
["f"]=>
string(5) "value"
["h"]=>
bool(false)
}
Example #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)
}
Example #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)
}
|
more
Recently updated
more
Most requested
more
Last requests
|