Link to home
Start Free TrialLog in
Avatar of zattz
zattz

asked on

PHP windows cmd line variable

Hi

Can somebody show me how to make a php script that I can run from the windows command line and pass a variable to it.

A simple example is a script that echo's whatever variable was passed to it from the command line

Thanks
ASKER CERTIFIED SOLUTION
Avatar of joachim.claeys@teleatlas.com
joachim.claeys@teleatlas.com
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zattz
zattz

ASKER

C:\php>php.exe script.php 1a 2b 3c 4d
PHP Parse error:  parse error, unexpected ')', expecting ',' or ';' in C:\php\sc
ript.php on line 5
X-Powered-By: PHP/4.4.4
Content-type: text/html

I removed the ")" on line 5 and I get

C:\php>php.exe script.php 1a 2b 3c 4d
PHP Notice:  Undefined variable:  argv in C:\php\script.php on line 2
X-Powered-By: PHP/4.4.4
Content-type: text/html
Sorry about the typing error.

Make sure you read the introduction of the referenced php link "http://us3.php.net/features.commandline"

Depending on your PHP version / build, it's possible that you need to change php.ini settings to be able to access the argv array.

(  e.g register_argc_argv TRUE )



Avatar of zattz

ASKER

I do apologise, I totally skipped over the link.

It's working now that I edited my php.ini to say register_argc_argv = on

Thanks:)