This question is regarding getopt function in php. I need to pass two parameter to the php scripts like
php script.php -f filename -t filetype
If you just put something like this in your PHP script (called, on my machine, temp.php
) :
And call it from the command-line, passing those two parameters :
php temp.php -f filename -t filetype
You'll get this kind of output :
array(2) {
["f"]=>
string(8) "filename"
["t"]=>
string(8) "filetype"
}
Which means that :
$file['f']
contains the value passed for -f
$file['t']
contains the value passed for -t
Starting from there, if you want your switch
to depend on the option passed as the value of -t
, you'll use something like this :
switch ($file['t']) {
case 'u':
// ...
break;
case 'c':
// ...
break;
case 'i':
// ...
break;
}
Basically, you put :
switch()
case
s
And, for more informations, you can read, in the PHP manual :