本文整理汇总了PHP中Console_Getopt::_isLongOpt方法的典型用法代码示例。如果您正苦于以下问题:PHP Console_Getopt::_isLongOpt方法的具体用法?PHP Console_Getopt::_isLongOpt怎么用?PHP Console_Getopt::_isLongOpt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Console_Getopt
的用法示例。
在下文中一共展示了Console_Getopt::_isLongOpt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _parseShortOption
/**
* @access private
*
*/
function _parseShortOption($arg, $short_options, &$opts, &$args)
{
for ($i = 0; $i < strlen($arg); $i++) {
$opt = $arg[$i];
$opt_arg = null;
/* Try to find the short option in the specifier string. */
if (($spec = strstr($short_options, $opt)) === false || $arg[$i] == ':') {
return PEAR::raiseError("Console_Getopt: unrecognized option -- {$opt}");
}
if (strlen($spec) > 1 && $spec[1] == ':') {
if (strlen($spec) > 2 && $spec[2] == ':') {
if ($i + 1 < strlen($arg)) {
/* Option takes an optional argument. Use the remainder of
the arg string if there is anything left. */
$opts[] = array($opt, substr($arg, $i + 1));
break;
}
} else {
/* Option requires an argument. Use the remainder of the arg
string if there is anything left. */
if ($i + 1 < strlen($arg)) {
$opts[] = array($opt, substr($arg, $i + 1));
break;
} else {
if (list(, $opt_arg) = each($args)) {
/* Else use the next argument. */
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
return PEAR::raiseError("Console_Getopt: option requires an argument -- {$opt}");
}
} else {
return PEAR::raiseError("Console_Getopt: option requires an argument -- {$opt}");
}
}
}
}
$opts[] = array($opt, $opt_arg);
}
}
示例2: _parseLongOption
/**
* @access private
*
*/
function _parseLongOption($arg, $long_options, &$opts, &$args)
{
@(list($opt, $opt_arg) = explode('=', $arg, 2));
$opt_len = strlen($opt);
for ($i = 0; $i < count($long_options); $i++) {
$long_opt = $long_options[$i];
$opt_start = substr($long_opt, 0, $opt_len);
$long_opt_name = str_replace('=', '', $long_opt);
/* Option doesn't match. Go on to the next one. */
if ($long_opt_name != $opt) {
continue;
}
$opt_rest = substr($long_opt, $opt_len);
/* Check that the options uniquely matches one of the allowed
options. */
if ($i + 1 < count($long_options)) {
$next_option_rest = substr($long_options[$i + 1], $opt_len);
} else {
$next_option_rest = '';
}
if ($opt_rest != '' && $opt[0] != '=' && $i + 1 < count($long_options) && $opt == substr($long_options[$i + 1], 0, $opt_len) && $next_option_rest != '' && $next_option_rest[0] != '=') {
throw new Exception("Console_Getopt: option --{$opt} is ambiguous");
}
if (substr($long_opt, -1) == '=') {
if (substr($long_opt, -2) != '==') {
/* Long option requires an argument.
Take the next argument if one wasn't specified. */
if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
throw new Exception("Console_Getopt: option --{$opt} requires an argument");
}
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
throw new Exception("Console_Getopt: option requires an argument --{$opt}");
}
}
} else {
if ($opt_arg) {
throw new Exception("Console_Getopt: option --{$opt} doesn't allow an argument");
}
}
$opts[] = array('--' . $opt, $opt_arg);
return;
}
throw new Exception("Console_Getopt: unrecognized option --{$opt}");
}