Results 1 to 4 of 4

Thread: PHP command line arguments

  1. #1
    Join Date
    Jul 2009
    Posts
    79

    PHP command line arguments

    I have Linux been installed on my system. On that i use PHP and also had used the command-line interface, let say for example "# php crap.php". Now, i wanted to know that is it possible for me to pass php command-line arguments to a php script? Does any body knows about it? Let me know your views on the above issue. Any help you can provide would be greatly appreciated.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: PHP command line arguments

    PHP has the getopt() function for getting options or command line arguments from a CLI PHP script. PHP Command Line Interface. As the name implies, this is a way of using PHP in the system command line. This provides a simple way to get values from the command line like e.g. "-a foo".

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: PHP command line arguments

    The command itself (i.e. your script filename) and the command line arguments are stored in an array in the $_SERVER variables called 'argv'. If you have standard installation of PHP for Apache web server, then there are very high chances that you already have PHP CLI installed on your system.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: PHP command line arguments

    $argv is "argument value". It is possible to access the command line arguments from here but it's easier to getopt() because you can then access the arguments by flag and in any order. Running the command "php myscript.php foo bar" and then doing print_r($_SERVER['argv']) would output this: It's an array that contains an argument (as a string) in each array key, with the name of the script being in $argv[0] and the arguments passed being held after that.

    Example:-
    "# php crap.php crap rocks"
    $argv[0] = "crap.php"
    $argv[1] = "crap"
    $argv[2] = "rocks"

Similar Threads

  1. Replies: 3
    Last Post: 28-10-2010, 12:16 PM
  2. xcopy command line together with wmplayer command line
    By Aislinn in forum Operating Systems
    Replies: 5
    Last Post: 31-03-2010, 12:13 PM
  3. Command Line Arguments in java
    By Vipul03 in forum Software Development
    Replies: 2
    Last Post: 22-02-2010, 04:39 PM
  4. What are Command-Line Arguments in Java?
    By Beter 2 Burn Out in forum Software Development
    Replies: 8
    Last Post: 20-02-2010, 03:37 PM
  5. Replies: 2
    Last Post: 08-07-2009, 12:11 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,399,801.19855 seconds with 17 queries