note 100573 added to function.getopt

From: Date: Sun, 24 Oct 2010 20:39:42 +0000
Subject: note 100573 added to function.getopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-173417@lists.php.net to get a copy of this message
Here's another way of removing options found by getopt() from the argv[] array. It handles the different kind of parameters without eating chunks that do not belong to an --option. (-nr foo param1 param2 foo) <?php $parameters = array( 'n' => 'noparam', 'r:' => 'required:', 'o::' => 'optional::', ); $options = getopt(implode('', array_keys($parameters)), $parameters); $pruneargv = array(); foreach ($options as $option => $value) { foreach ($argv as $key => $chunk) { $regex = '/^'. (isset($option[1]) ? '--' : '-') . $option . '/'; if ($chunk == $value && $argv[$key-1][0] == '-' || preg_match($regex, $chunk)) { array_push($pruneargv, $key); } } } while ($key = array_pop($pruneargv)) unset($argv[$key]); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 134.130.4.243 (proxied: 137.226.149.42) ---- Manual Page -- http://www.php.net/manual/en/function.getopt.php Edit -- https://master.php.net/note/edit/100573 Del: integrated -- https://master.php.net/note/delete/100573/integrated Del: useless -- https://master.php.net/note/delete/100573/useless Del: bad code -- https://master.php.net/note/delete/100573/bad+code Del: spam -- https://master.php.net/note/delete/100573/spam Del: non-english -- https://master.php.net/note/delete/100573/non-english Del: in docs -- https://master.php.net/note/delete/100573/in+docs Del: other reasons-- https://master.php.net/note/delete/100573 Reject -- https://master.php.net/note/reject/100573 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173417) next »