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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'd do: grep -E 'self\.timeout[ \t]*=[ \t]*[0-9.]+' note: | |… May 16, 2026 at 2:38 pm
  • Editorial Team
    Editorial Team added an answer As answered on #django, likely because embedded mode being used… May 16, 2026 at 2:38 pm
  • Editorial Team
    Editorial Team added an answer As Stefan and Moreno pointed, there was indeed a problem… May 16, 2026 at 2:38 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a question regarding GetTickCount function, I have two calls to this function
This question relates to the schema I suggested in my original question regarding a
Yesterday I posted this question regarding using lambdas inside of a Join() method to
Following on from this question , regarding accessing a PDF on a web page
Yesterday, I asked this question regarding best practices for a simple information retrieval system
I was looking at the answer of this question regarding multiple generic types in
A while back I posted a different question regarding column order. While this question
It is a question regarding Subgurim Google Maps wrapper in ASP.NET. I would like
I have a question regarding n-layer architecture. I thought long and hard before asking
G'day, This is related to my question on star developers and to this question

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.