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 8109447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:25:15+00:00 2026-06-06T01:25:15+00:00

I want to pass parameters from PHP Command Line Interface, and then read in

  • 0

I want to pass parameters from PHP Command Line Interface, and then read in the values using PHP script, something like this:

<?php
  $name1 = $argv[1];    
  echo $name1;
?>

I pass the variable from CLI like this:

C:\xampp\php\php.exe name.php Robby

The above works, I get Robby as the output.

But I want to do something like this:

C:\xampp\php\php.exe name.php -inputFirstName="Robby"

So that the user is well informed to enter the correct parameters in the correct places. What is the appropriate way to parse these parameters?

  • 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-06-06T01:25:17+00:00Added an answer on June 6, 2026 at 1:25 am

    When calling a PHP script from the command line you can use $argc to find out how many parameters are passed and $argv to access them. For example running the following script:

    <?php
        var_dump($argc); //number of arguments passed 
        var_dump($argv); //the arguments passed
    ?>
    

    Like this:-

    php script.php arg1 arg2 arg3
    

    Will give the following output

    int(4)
    array(4) {
      [0]=>
      string(21) "d:\Scripts\script.php"
      [1]=>
      string(4) "arg1"
      [2]=>
      string(4) "arg2"
      [3]=>
      string(4) "arg3"
    }
    

    See $argv and $argc for further details.

    To do what you want, lets say

    php script.php arg1=4
    

    You would need to explode the argument on the equals sign:-

    list($key, $val) = explode('=', $argv[1]);
    var_dump(array($key=>$val));
    

    That way you can have whatever you want in front of the equals sign without having to parse it, just check the key=>value pairs are correct. However, that is all a bit of a waste, just instruct the user on the correct order to pass the arguments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass several parameters to this url and generate the map from
Im trying to pass some variables from the URL to the PHP script. Now
I want to pass parameters to reportviewer control from the page I built with
how can i pass parameters from an html page(map.html) to a php(createxml.php) without having
I need to pass an array of numeric values from jQuery to a php
I want to pass these parameters with a HTTP request to a WebApp hosted
I want to create a alias method in ruby and pass parameters to this.
Here I only want to pass a custom class or only parameters into a
I want to pass the parameter which is rentalPeriod using Html.BeginForm. Currently, I put
I am trying to pass parameters from one action (foo) to another (foobar). In

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.