note 56543 added to function.getopt
| From: | nutbar at innocent dot com | Date: | Tue, 06 Sep 2005 18:40:26 +0000 |
| Subject: | note 56543 added to function.getopt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94831@lists.php.net to get a copy of this message | ||
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()).
----
Manual Page -- http://www.php.net/manual/en/function.getopt.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56543
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56543&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56543&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56543&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56543&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56543&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56543&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56543&report=yes
Search -- http://master.php.net/manage/user-notes.php