note 101713 added to function.getopt

From: Date: Thu, 06 Jan 2011 13:39:20 +0000
Subject: note 101713 added to function.getopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-175488@lists.php.net to get a copy of this message
I ported GNU Getopt to PHP. It supports short and long opts and its behavior is nearly identical to the java port. Here's a snippet which implements the class: #!/usr/bin/php <?php require_once("gnu/getopt/Getopt.php"); require_once("gnu/getopt/Longopt.php"); $longopt = array(); $longopt[0] = new LongOpt("help", NO_ARGUMENT, null, 'h'); $longopt[1] = new LongOpt("about", REQUIRED_ARGUMENT, null, 'a'); $getopt = new Getopt($argv, "a:bc:d:hW;", $longopt); $c; $arg; while (($c = $getopt->getopts()) != -1) { switch($c) { case 'a': case 'd': $arg = $getopt->getOptarg(); print("You picked $c with an argument of ".(($arg != null) ? $arg : "null")."\n"); break; case 'b': case 'c': $arg = $getopt->getOptarg(); print("You picked $c with an argument of ".(($arg != null) ? $arg : "null") . "\n"); break; case 'h': print "Usage: test [options] \n"; break; case '?': break; // getopt() already printed an error default: print("getopt() returned $c\n"); } } ?> For the code go here: http://www.joedog.org/index/articles-gnu-getopt ---- Server IP: 208.69.120.55 Probable Submitter: 69.55.236.229 ---- Manual Page -- http://www.php.net/manual/en/function.getopt.php Edit -- https://master.php.net/note/edit/101713 Del: integrated -- https://master.php.net/note/delete/101713/integrated Del: useless -- https://master.php.net/note/delete/101713/useless Del: bad code -- https://master.php.net/note/delete/101713/bad+code Del: spam -- https://master.php.net/note/delete/101713/spam Del: non-english -- https://master.php.net/note/delete/101713/non-english Del: in docs -- https://master.php.net/note/delete/101713/in+docs Del: other reasons-- https://master.php.net/note/delete/101713 Reject -- https://master.php.net/note/reject/101713 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175488) next »