Jump to content

passing variable from command line?


swellinfo

Recommended Posts

no, I'd like to define a variable ($pre) outside of the script. 

So, where I am executing my script from a linux command line:
php myscript.php

Is there a way to pass a variable to the script from the command line, or do I just need to create another file, and do an include?

I figured this out:

Passing variables on the command line is different than from a url, where you would type

http://www.domain.com/myscript?var=whatever

instead, on the command line, you type

php myscript.php whatever     

you put a space in between the script and the value you are passing, and that value is available in the $argv variable.
$argv is an array, and the first value is always the name of the script, and in this example case the second value would be "whatever". 
- $argv[1] = "whatever". 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.