note 114587 added to function.getopt
| From: | takingsides at gmail dot com | Date: | Sun, 09 Mar 2014 15:17:00 +0000 |
| Subject: | note 114587 added to function.getopt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198843@lists.php.net to get a copy of this message | ||
As already mentioned getopt() will stop parsing options upon the '--'. Sometimes you will
have options and arguments but the user may not always provide the explicit -- option.
Below is a quick way to collect options and arguments regardless of the -- consistently.
#!/usr/bin/php
<?php
$options = getopt('hl::m:v:a', [
'help',
'list::',
'module:',
'version:',
'all',
]);
var_dump( $options );
$args = array_search('--', $argv);
$args = array_splice($argv, $args ? ++$args : (count($argv) - count($opt)));
var_dump( $args );
?>
----
Server IP: 87.117.229.81
Probable Submitter: 176.26.99.186
----
Manual Page -- http://php.net/manual/en/function.getopt.php
Edit -- https://master.php.net/note/edit/114587
Del: integrated -- https://master.php.net/note/delete/114587/integrated
Del: useless -- https://master.php.net/note/delete/114587/useless
Del: bad code -- https://master.php.net/note/delete/114587/bad+code
Del: spam -- https://master.php.net/note/delete/114587/spam
Del: non-english -- https://master.php.net/note/delete/114587/non-english
Del: in docs -- https://master.php.net/note/delete/114587/in+docs
Del: other reasons-- https://master.php.net/note/delete/114587
Reject -- https://master.php.net/note/reject/114587
Search -- https://master.php.net/manage/user-notes.php