note 56543 deleted from function.getopt by danbrown
| From: | danbrown@php.net | Date: | Sat, 27 Dec 2008 17:52:13 +0000 |
| Subject: | note 56543 deleted from function.getopt by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148584@lists.php.net to get a copy of this message | ||
Note Submitter: nutbar at innocent dot com
----
The code snippet that daevid at daevid dot com gives works, however is not a perfect getopt
replacement since you cannot use the "default" switch statement.
Usage: prog [OPTIONS] <req'd argument> <req'd argument>
The switch() call will eventually run on those 2 required arguments. If you use the
"default" statement, it will catch the argument and chances are you use the default
statement as your --help trap, thus it will exit the script (if that's what you do).
So, if you use that example below, you may want to check each "argv" variable, and if it
doesn't match --*, then you may want to skip past it and store it in another array for
retrieval as a required argument if your script uses those.
I will be writing a getopt class that will do everything properly possibly, if/when I do, I'll
post it up here so you can all use it rather than the built in getopt code (seems a bit limiting
compared to the actual C library getopt_long()).