Jump to content

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". 
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.