note 81042 added to features.commandline
| From: | technorati at gmail dot com | Date: | Tue, 12 Feb 2008 14:21:07 +0000 |
| Subject: | note 81042 added to features.commandline | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136065@lists.php.net to get a copy of this message | ||
Here's an update to the script a couple of people gave below to read arguments from $argv of
the form --name=VALUE and -flag. Changes include:
Don't use $_ARG - $_ is generally considered reserved for the engine.
Don't use regex where a string operation will do just as nicely
Don't overwrite --name=VALUE with -flag when 'name' and 'flag' are the same
thing
Allow for VALUE that has an equals sign in it
function arguments($argv) {
$ARG = array();
foreach ($argv as $arg) {
if (strpos($arg, '--') === 0) {
$compspec = explode('=', $arg);
$key = str_replace('--', '', array_shift($compspec));
$value = join('=', $compspec);
$ARG[$key] = $value;
} elseif (strpos($arg, '-') === 0) {
$key = str_replace('-', '', $arg);
if (!isset($ARG[$key])) $ARG[$key] = true;
}
}
return $ARG;
}
----
Server IP: 64.71.164.2
Probable Submitter: 76.27.50.131
----
Manual Page -- http://www.php.net/manual/en/features.commandline.php
Edit -- https://master.php.net/note/edit/81042
Del: integrated -- https://master.php.net/note/delete/81042/integrated
Del: useless -- https://master.php.net/note/delete/81042/useless
Del: bad code -- https://master.php.net/note/delete/81042/bad+code
Del: spam -- https://master.php.net/note/delete/81042/spam
Del: non-english -- https://master.php.net/note/delete/81042/non-english
Del: in docs -- https://master.php.net/note/delete/81042/in+docs
Del: other reasons-- https://master.php.net/note/delete/81042
Reject -- https://master.php.net/note/reject/81042
Search -- https://master.php.net/manage/user-notes.php