Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 656061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:40:23+00:00 2026-05-13T22:40:23+00:00

This question is regarding getopt function in php. I need to pass two parameter

  • 0

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

Now depending upon the file type which can be u, c or s I need to do proper operation.

I am using switch case for the same:

Here is the Code I am using:

// Get filename of input file when executing through command line.
$file = getopt("f:t:");

Switch case should compare the type of the file which I am passing in from the command line (u, c or i) and accordingly match it and do the operation.

switch("I am not sure what should go in there and this is wrong,Please advice")
    {

        case `Not sure`:
            $p->ini();
            break;

        case `Not sure`:
            $p->iniCon();
            break;

        case `Not sure`:
            $p->iniImp();
            break;
    }

Kindly advise on this !!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:40:23+00:00Added an answer on May 13, 2026 at 10:40 pm

    If you just put something like this in your PHP script (called, on my machine, temp.php) :

    <?php
    $file = getopt("f:t:");
    var_dump($file);
    

    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
    • and $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 :

    • The variable that you want to test in the switch()
    • And the possible values in the cases

    And, for more informations, you can read, in the PHP manual :

    • The manual page of switch
    • And getopt()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

another newbie-question regarding rails and bootstrap. I am using something like this: <div class=tabbable
This question is regarding wordpress . I have two variables $random_n and $adcount declared
While answering this question regarding safe escaping of filename with spaces (and potentially other
This is a question regarding Ajax Iframes. I have a function to open an
This is a question regarding best coding practices. I would like to know the
I have a question regarding this topic.Like for Client Server Applications 1) is it
This is my first question regarding PHP so please bear with me. I've been
Yesterday I posted this question regarding using lambdas inside of a Join() method to
Yesterday, I asked this question regarding best practices for a simple information retrieval system
This is a question regarding the timezone specified in the Expires and Last-Modified HTTP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.