本文整理汇总了PHP中Console_Getopt::_parseLongOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Console_Getopt::_parseLongOption方法的具体用法?PHP Console_Getopt::_parseLongOption怎么用?PHP Console_Getopt::_parseLongOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Console_Getopt
的用法示例。
在下文中一共展示了Console_Getopt::_parseLongOption方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getopt
/**
* Parses the command-line options.
*
* The first parameter to this function should be the list of command-line
* arguments without the leading reference to the running program.
*
* The second parameter is a string of allowed short options. Each of the
* option letters can be followed by a colon ':' to specify that the option
* requires an argument, or a double colon '::' to specify that the option
* takes an optional argument.
*
* The third argument is an optional array of allowed long options. The
* leading '--' should not be included in the option name. Options that
* require an argument should be followed by '=', and options that take an
* option argument should be followed by '=='.
*
* The return value is an array of two elements: the list of parsed
* options and the list of non-option command-line arguments. Each entry in
* the list of parsed options is a pair of elements - the first one
* specifies the option, and the second one specifies the option argument,
* if there was one.
*
* Long and short options can be mixed.
*
* Most of the semantics of this function are based on GNU getopt_long().
*
* @param $args array an array of command-line arguments
* @param $short_options string specifies the list of allowed short options
* @param $long_options array specifies the list of allowed long options
*
* @return array two-element array containing the list of parsed options and
* the non-option arguments
*
* @access public
*
*/
public static function getopt($args, $short_options, $long_options = null)
{
$opts = array();
$non_opts = array();
settype($args, 'array');
if ($long_options) {
sort($long_options);
}
reset($args);
while (list(, $arg) = each($args)) {
/* The special element '--' means explicit end of options. Treat the
rest of the arguments as non-options and end the loop. */
if ($arg == '--') {
$non_opts = array_merge($non_opts, array_slice($args, $i + 1));
break;
}
if ($arg[0] != '-' || $arg[1] == '-' && !$long_options) {
$non_opts[] = $arg;
} else {
if ($arg[1] == '-') {
if (!Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args)) {
return false;
}
} else {
if (!Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args)) {
return false;
}
}
}
}
return array($opts, $non_opts);
}
示例2: doGetopt
/**
* The actual implementation of the argument parsing code.
*/
function doGetopt($version, $args, $short_options, $long_options = null)
{
// in case you pass directly readPHPArgv() as the first arg
if (PEAR::isError($args)) {
return $args;
}
if (empty($args)) {
return array(array(), array());
}
$opts = array();
$non_opts = array();
settype($args, 'array');
if ($long_options) {
sort($long_options);
}
/*
* Preserve backwards compatibility with callers that relied on
* erroneous POSIX fix.
*/
if ($version < 2) {
if (isset($args[0][0]) && $args[0][0] != '-') {
array_shift($args);
}
}
reset($args);
while (list($i, $arg) = each($args)) {
/* The special element '--' means explicit end of
options. Treat the rest of the arguments as non-options
and end the loop. */
if ($arg == '--') {
$non_opts = array_merge($non_opts, array_slice($args, $i + 1));
break;
}
if ($arg[0] != '-' || strlen($arg) > 1 && $arg[1] == '-' && !$long_options) {
$non_opts = array_merge($non_opts, array_slice($args, $i));
break;
} elseif (strlen($arg) > 1 && $arg[1] == '-') {
$error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
if (PEAR::isError($error)) {
return $error;
}
} else {
$error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
if (PEAR::isError($error)) {
return $error;
}
}
}
return array($opts, $non_opts);
}