Hi there - is there any way to access the a variable name passed to a php script as follows
url/test.php?gorilla
What I want to do is display the word that is passed to the script(in the case above it would be 'gorilla'). I don't believe I can use $_REQUEST for this as it is an associative array. I've tried $_SERVER['argv'] with an index of 0 but with no result.
Thanks in advance.
newbie question accessing argv
Moderator: General Moderators
-
millerthegorilla
- Forum Newbie
- Posts: 3
- Joined: Mon May 26, 2008 12:32 pm
-
impulse()
- Forum Regular
- Posts: 748
- Joined: Wed Aug 09, 2006 8:36 am
- Location: Staffordshire, UK
- Contact:
Re: newbie question accessing argv
Also, just to add. The argv variable is for CLI-PHP so it can pick up on parameters passed in from the shell.
EG:
php example.php stephen richards
stephen would then become $_argv[1] and richards would become $_argv[2] in the script. $_argv[0] is reserved for the script name.
EG:
php example.php stephen richards
stephen would then become $_argv[1] and richards would become $_argv[2] in the script. $_argv[0] is reserved for the script name.
-
millerthegorilla
- Forum Newbie
- Posts: 3
- Joined: Mon May 26, 2008 12:32 pm
Re: newbie question accessing argv
Thanks for your response but using $_GET won't work any more than $_REQUEST. They are both associative arrays so I can't use an index to access the first entry. It has to be accessed using the name of a name/value pair ie $_GET['name'] will return the value.
What I want to do is access the first element of the array with an index. I am not using the command line, I am using a server side script but I thought you could access the argv variable of $_SERVER as follows: $_SERVER['argv'] which I thought in this case would return 'name'. But it doesn't. I'm not sure if there's a way to do this as I think php is designed to be passed name/value pairs from an http submit.
What I want to do is access the first element of the array with an index. I am not using the command line, I am using a server side script but I thought you could access the argv variable of $_SERVER as follows: $_SERVER['argv'] which I thought in this case would return 'name'. But it doesn't. I'm not sure if there's a way to do this as I think php is designed to be passed name/value pairs from an http submit.
-
millerthegorilla
- Forum Newbie
- Posts: 3
- Joined: Mon May 26, 2008 12:32 pm
Re: newbie question accessing argv
I've just sussed it out. You need to use $_SERVER[QUERY_STRING].