Re: Command Line Arguments Don't Work

From: Date: Tue, 07 Nov 2000 02:42:35 +0000
Subject: Re: Command Line Arguments Don't Work
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-24043@lists.php.net to get a copy of this message
What do you mean? if you put: #!/usr/local/bin/php -q <?php echo $argc ?> ...into a file and execute it like this: ./filename first_arg second_arg third_arg it'll print out: 4 if you put: #!/usr/local/bin/php -q <?php for ($i=0;$i<count($argv);$i++) echo $argv[$i]."\n" ?> ...into a file and execute it like this: ./filename first_arg second_arg third_arg it'll print out: ./filename.php first_arg second_arg third_arg I don't understand why you say that the manual would encourage you to try the things you state. There's a couple of reasons I say that - one is that it clearly says that argv is an array, so why would you feel inclined to try and echo it by name instead of accessing it's elements? Another is that that page says the c-style command-line parms are availanble when you run a script from the command-line, so why would you try and access them through HTTP_ENV_VARS - it has nothing to do with http in this situation. The only time it mentions anything about http is where it says GET - but it's still an array. jason > To clarify here a bit: > > Reading the manual entry Jason links to might encourage you to try these > options: > > echo $argv; > echo $GLOBALS["argv"]; > echo $HTTP_ENV_VARS["argv"]; > echo $HTTP_ENV_VARS["argc"]; > print_r($HTTP_ENV_VARS); > > You'll have no luck getting anything to print that resembles a command > line option. > > The trick from John Donagher appears to be to use HTTP_SERVER_VARS. > > After coding in PHP for a few years now I'd never mastered this little > trick, my unix background kept me thinking that command line variables > were part of the enviroment. Whooops. No I know the truth. > > August

« previous php.general (#24043) next »