Operating System - OpenVMS
1753766 Members
5594 Online
108799 Solutions
New Discussion юеВ

Re: Paramater passing - PHP

 
SOLVED
Go to solution
Paul Beaudoin
Regular Advisor

Paramater passing - PHP

Gents,

Further to my last thread in which I got PHP to work at DCL level, I now need to know how to pass paramaters to a PHP script called from DCL. I assume this can be done but can't find any references either on the web or in the manual.

Thanks for any hints

Regards

Paul
PS. for anyone interested, I am experimenting with the FPDF package to create PDFs from text files. With some interesting anomolies, it seems to work well and I can recommend it (so far!)

PB
5 REPLIES 5
Wim Van den Wyngaert
Honored Contributor
Solution

Re: Paramater passing - PHP

Somewhere on this forum I posted txt2pdf that I corrected to show larger files too (e.g. 300 char/line listings we like to show on the screen).

I also saw a2html that converts normal listings with cobol style tables to html with tables (that you can move to XL with the right mouse button).

Fwiw

Wim
Wim
Robert Atkinson
Respected Contributor

Re: Paramater passing - PHP

Paul, this is documented at http://uk2.php.net/manual/en/features.commandline.php (including some useful examples) :-

"Like every shell application, the PHP binary accepts a number of arguments but your PHP script can also receive arguments. The number of arguments which can be passed to your script is not limited by PHP (the shell has a certain size limit in the number of characters which can be passed; usually you won't hit this limit). The arguments passed to your script are available in the global array $argv. The zero index always contains the script name (which is - in case the PHP code is coming from either standard input or from the command line switch -r). The second registered global variable is $argc which contains the number of elements in the $argv array (not the number of arguments passed to the script)."

Rob.

Paul Beaudoin
Regular Advisor

Re: Paramater passing - PHP

Wim

Ummm... wow... that (at first attempt!) seems to do the trick. 20 out of 10!

Thanks muchly

(Though for general interest I'd still like to know how to pass the params so I don't have to ask again in another contect)

Best regards

Paul
Paul Beaudoin
Regular Advisor

Re: Paramater passing - PHP

Robert,
I'm sorry - I missed your message earlier- it is entirely correct as I since discovered. Using this call:
php test_param.php P1=1 P2=2 P3=3

Where the file is:
print_r($argv);
print_r($argc);
?>

Produces:


Content-type: text/html
X-Powered-By: PHP/4.3.2



Array
(
[0] => test_param.php
[1] => p1=1
[2] => p2=2
[3] => p3=3
)

As you can see, arg 0 is the script name followed by args 1-n in the array. I bet if I echoed $argc it would have given the correct result.
Many thanks

Paul
Paul Beaudoin
Regular Advisor

Re: Paramater passing - PHP

Thanks to all for the replies - original problem solved and a possibly better solution found! Doesn't get better than that.