PHP file.php arg1 arg2
Now I want to hardcode arg1 and arg2 into file.php,how to do it?
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.
I never tried it, but the arguments are contained in a certain array
$argv. So you have to set those entries if you want to hardcode them:$argvis a reserved variable.But note that the first two parameter that you specify via command line will always be overwritten by
arg1andarg2.Instead, if you need these values always in your script you should define them as normal variables at the top of your script:
or even as constants:
If you only want to provide
arg1,arg2as parameter via the command line, then you can just access them via$argv[1]and$argv[2], no need to mess with$argv;