FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Converting Perl to PHP, testing CLI with $_POST (newbie)
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Converting Perl to PHP, testing CLI with $_POST (newbie) [message #172076 is a reply to message #172075] Sun, 30 January 2011 03:49 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 1/29/2011 10:09 PM, P E Schoen wrote:
> I have made much progress converting my working Perl script to the
> equivalent in PHP. Mostly I used the -l lint switch from the command
> line interface on my localhost Apache server, and I was able to pass the
> syntax check. Then I ran the script using a batch file with command line
> arguments as CGI variables, but they do not seem to be read into the
> $_POST array. My batch file is as follows:
>
> C:\xampp\php\php-cgi eventprocessor.php --
> Full_Name="MyName";Email="MyEmail"; ...
>
> I am attempting to read the variables as
>
> $in = $_POST ; // Get the CGI input variables
> echo("Name: " . $_POST["Full_Name"] . "\n");
> echo("Name: " . $in[Full_Name] . "\n");
> echo("Name: " . $argv[2] . "\n");
>
> This is essentially what I used for the Perl script and it works fine.
> The last line above echoes the entire set of CGI variables (since there
> are no spaces), and #argv[1] is just "--". I also used the command line
> eventprocessor.php < CGIVARS.txt, but that did not work.
>
> This did not seem to help:
> http://php.net/manual/en/features.commandline.options.php
>
> I should be able to use an HTML form and use POST to run the script, but
> there should be a way directly from the CLI as there was for Perl.
>
> So far I have found PHP much easier to use than Perl, so if I can get
> past this hurdle I will be well on my way to make a determination as to
> what language I will use for scripting.
>
> Thanks,
>
> Paul

Paul, unfortunately the $_POST array is set up by the php web interface,
not the CLI (and argv/argc are set up by the CLI and not the web
interface, by default).

I normally test on my local web server; you could do a quick test of the
code by wrapping it in a quick interface which fills in the value, but
that still won't show you the formatted output (or even determine if the
$_POST variables are set up properly.

Best is still to have a local development web site which closely mimics
that of your production server (i.e. similar versions of PHP, MySQL,
etc.) and test on it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: passing variable to a nested array
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 12:43:26 GMT 2024

Total time taken to generate the page: 0.04071 seconds