parameters and commandline

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Gausa

    parameters and commandline

    hi
    i want to start a php programm from commandline and pass some parameters to
    the programm. but the programm did not recognize the parameters.

    the commandline ist: php liste.php para1=one para2=two

    the source (list.php)

    ....
    echo $_request[para1];
    echo $_request[para2];
    ....

    why does this not work?

  • Ken Robinson

    #2
    Re: parameters and commandline


    Alexander Gausa wrote:[color=blue]
    > hi
    > i want to start a php programm from commandline and pass some[/color]
    parameters to[color=blue]
    > the programm. but the programm did not recognize the parameters.
    >
    > the commandline ist: php liste.php para1=one para2=two
    >
    > the source (list.php)
    >
    > ...
    > echo $_request[para1];
    > echo $_request[para2];
    > ...
    >
    > why does this not work?[/color]

    When using PHP from the command line you need to use the array $argv.
    The $_REQUEST superglobal is only available when running via a web
    server.

    For example:
    cmdline.php contains:
    <?
    print_r ($argv);
    ?>

    When run from the command line:
    php -q cmdline.php para1=one para2=two

    The results are:
    Array
    (
    [0] => cmdline.php
    [1] => para1=one
    [2] => para2=two
    )


    Ken

    Comment

    • Alexander Gausa

      #3
      Re: parameters and commandline

      Thanks, it is working!

      Ken Robinson wrote:
      [color=blue]
      >
      > Alexander Gausa wrote:[color=green]
      >> hi
      >> i want to start a php programm from commandline and pass some[/color]
      > parameters to[color=green]
      >> the programm. but the programm did not recognize the parameters.
      >>
      >> the commandline ist: php liste.php para1=one para2=two
      >>
      >> the source (list.php)
      >>
      >> ...
      >> echo $_request[para1];
      >> echo $_request[para2];
      >> ...
      >>
      >> why does this not work?[/color]
      >
      > When using PHP from the command line you need to use the array $argv.
      > The $_REQUEST superglobal is only available when running via a web
      > server.
      >
      > For example:
      > cmdline.php contains:
      > <?
      > print_r ($argv);
      > ?>
      >
      > When run from the command line:
      > php -q cmdline.php para1=one para2=two
      >
      > The results are:
      > Array
      > (
      > [0] => cmdline.php
      > [1] => para1=one
      > [2] => para2=two
      > )
      >
      >
      > Ken[/color]

      Comment

      Working...