note 1931 modified in language.variables.external by philip
| From: | philip@php.net | Date: | Mon, 08 Jul 2002 17:38:57 +0000 |
| Subject: | note 1931 modified in language.variables.external by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-32742@lists.php.net to get a copy of this message | ||
Concerning parameters on the command-line: If you are trying to run a php-script as a shell command,
you can add this function to your code to get access to the parameters on the command-line:
function get_commandline()
{
global $HTTP_SERVER_VARS;
for ($i=0; $i<$HTTP_SERVER_VARS['argc']; $i++)
{
$my_args = array();
if (ereg("(.*)=(.*)", $HTTP_SERVER_VARS['argv'][$i], $my_args))
{
$GLOBALS[$my_args[1]] = $my_args[2];
}
}
}
This parses the all the given parameters in a call like "test.php arg1=abc arg2=def" into
variables in the global scope, named as the arguments were ($arg1 is set now to "abc").
--was--
Concerning parameters on the command-line: If you are trying to run a php-script as a shell command,
you can add this function to your code to get access to the parameters on the command-line:
function get_commandline()
{
global $argc, $argv;
for ($i=0; $i<$argc; $i++)
{
$my_args = array();
if (ereg("(.*)=(.*)", $argv[$i], $my_args))
{
$GLOBALS[$my_args[1]] = $my_args[2];
}
}
}
This parses the all the given parameters in a call like "test.php arg1=abc arg2=def" into
variables in the global scope, named as the arguments were ($arg1 is set now to "abc").
http://www.php.net/manual/en/language.variables.external.php