my question is probably easy to answer. i want to execute my php file with shell and pass parameters to it via shell
example
php test.php parameter1 parameter2
is there a way to do that except using GET ?
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes you can do it like that but you should reference the arguments from the
$_SERVER['argv']array.$_SERVER['argc']will tell you how many args were received, should you want to use that as a first layer of validation to make sure a required number of args were input.To illustrate this, running the following script as
args.php arg1 arg2 arg3:will output:
Here is a practical example:
In this example, we’ll create a script (days.php) that outputs the number of days since a particular date. It will accept 3 parameters, the month, day, and year as numbers.
Shell call:
Output:
Hope this helps.