Php 从argv中删除getopt中找到的选项
有没有一种快速的方法可以使用getopt从$argv中删除找到的选项 基本上,我有Php 从argv中删除getopt中找到的选项,php,command-line-interface,getopt,Php,Command Line Interface,Getopt,有没有一种快速的方法可以使用getopt从$argv中删除找到的选项 基本上,我有 php trout.php --plugin dozer /opt/webapplications/Word/readme.log 在我的$options=getopt()中;我有 $argv有以下内容 Array ( [0] => --plugin [1] => dozer [2] => /opt/webapplications/Word/readme.log )
php trout.php --plugin dozer /opt/webapplications/Word/readme.log
在我的$options=getopt()中;我有
$argv有以下内容
Array
(
[0] => --plugin
[1] => dozer
[2] => /opt/webapplications/Word/readme.log
)
我想要$argv刚刚
Array
(
[0] => /opt/webapplications/Word/readme.log
)
我知道有array\u shift来弹出第一个数组元素,我以前也见过循环,循环通过$argv弹出所有元素,但是,我想知道是否有一种快速简便的方法可以用原生php实现这一点…这就是我最后使用的方法
function __construct($args) {
$this->options = getopt($this->shortopts, $this->longopts);
array_shift($args);
while(count($args) > 1) {
if (strpos($args[0], '-') !== false && strpos($args[0], '-') == 0) {
array_shift($args);
if(in_array($args[0], $this->options)) {
array_shift($args);
}
}
else {
break;
}
}
$this->args = $args;
}
它不考虑用“=”指定的选项,如:--plugin=dozer
function __construct($args) {
$this->options = getopt($this->shortopts, $this->longopts);
array_shift($args);
while(count($args) > 1) {
if (strpos($args[0], '-') !== false && strpos($args[0], '-') == 0) {
array_shift($args);
if(in_array($args[0], $this->options)) {
array_shift($args);
}
}
else {
break;
}
}
$this->args = $args;
}