note 85140 added to function.getopt

From: Date: Sat, 16 Aug 2008 17:28:11 +0000
Subject: note 85140 added to function.getopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-143561@lists.php.net to get a copy of this message
I really need long options but it's not supported in 5.2.6 on my Solaris box so I wrote an _getopt() to simulate getopt(). An example ======== a.php ======== #!/usr/local/bin/php <? include "getopt.inc"; $shortopts = "f:v::abc:hp"; $longopts = array( "required:", // Required value "optional::", // Optional value "option", // No value "opt", // No value ); $options = _getopt( $shortopts, $longopts); var_dump($options); ?> ====== end of a.php ====== then run the file a.php, # ./a.php -f "test 2" -ab --required "test 1" --optional="test 3" --option -v "test 4" -k array(7) { ["f"]=> string(6) "test 2" ["a"]=> bool(false) ["b"]=> bool(false) ["required"]=> string(6) "test 1" ["optional"]=> string(6) "test 3" ["option"]=> bool(false) ["v"]=> string(6) "test 4" } Source code is a bit longer and not allowed by this site. Please go to my page http://www.ntu.beautifulworldco.com/weblog/?p=526 for it. ---- Server IP: 208.69.120.35 Probable Submitter: 192.18.17.3 ---- Manual Page -- http://www.php.net/manual/en/function.getopt.php Edit -- https://master.php.net/note/edit/85140 Del: integrated -- https://master.php.net/note/delete/85140/integrated Del: useless -- https://master.php.net/note/delete/85140/useless Del: bad code -- https://master.php.net/note/delete/85140/bad+code Del: spam -- https://master.php.net/note/delete/85140/spam Del: non-english -- https://master.php.net/note/delete/85140/non-english Del: in docs -- https://master.php.net/note/delete/85140/in+docs Del: other reasons-- https://master.php.net/note/delete/85140 Reject -- https://master.php.net/note/reject/85140 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143561) next »