note 78093 added to features.commandline
| From: | losbrutosatfreedotfr at osu1 dot php dot net | Date: | Thu, 27 Sep 2007 12:54:32 +0000 |
| Subject: | note 78093 added to features.commandline | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130852@lists.php.net to get a copy of this message | ||
an another "another variant" :
<?php
function arguments($argv)
{
$_ARG = array();
foreach ($argv as $arg)
{
if (preg_match('#^-{1,2}([a-zA-Z0-9]*)=?(.*)$#', $arg, $matches))
{
$key = $matches[1];
switch ($matches[2])
{
case '':
case 'true':
$arg = true;
break;
case 'false':
$arg = false;
break;
default:
$arg = $matches[2];
}
$_ARG[$key] = $arg;
}
else
{
$_ARG['input'][] = $arg;
}
}
return $_ARG;
}
?>
$php myscript.php arg1 -arg2=val2 --arg3=arg3 -arg4 --arg5 -arg6=false
Array
(
[input] => Array
(
[0] => myscript.php
[1] => arg1
)
[arg2] => val2
[arg3] => arg3
[arg4] => true
[arg5] => true
[arg5] => false
)
----
Server IP: 217.174.196.197
Probable Submitter: 81.255.192.131
----
Manual Page -- http://www.php.net/manual/en/features.commandline.php
Edit -- https://master.php.net/note/edit/78093
Del: integrated -- https://master.php.net/note/delete/78093/integrated
Del: useless -- https://master.php.net/note/delete/78093/useless
Del: bad code -- https://master.php.net/note/delete/78093/bad+code
Del: spam -- https://master.php.net/note/delete/78093/spam
Del: non-english -- https://master.php.net/note/delete/78093/non-english
Del: in docs -- https://master.php.net/note/delete/78093/in+docs
Del: other reasons-- https://master.php.net/note/delete/78093
Reject -- https://master.php.net/note/reject/78093
Search -- https://master.php.net/manage/user-notes.php