473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Pass equivalent $_POST[] array via command line

code green
1,726 Expert 1GB
The following code is part of a script actioned by a web form
[PHP]if(isset($_POST['report']))#the form has been submitted
{
if($pls = $_POST['pls']) #hidden variable in pricesCostForm
{
$levels = array();
for($c=0;$c<$pls;$c++)
{
if(isset($_POST['level'.$c]))
$levels[] = trim($_POST['level'.$c]);
} [/PHP] What do I add to the following command line
Expand|Select|Wrap|Line Numbers
  1. C:\apache\xampp\php\php-win.exe  "C:\apache\xampp\htdocs\programs\Reports\Prices\pricesReportEntry.php"
so that $_POST['report'] is set
$_POST['pls'] equals 45
and $_POST['level'.42] = 'TEST'
so that the above code will create the array
Expand|Select|Wrap|Line Numbers
  1. $levels[0=>'TEST'] 
This so the script can run via a scheduled task.
Thanks
Jun 3 '08 #1
6 5474
Atli
5,058 Expert 4TB
You should be able to fetch command line arguments via the $argv array. Like, if you type into the cmd window:
Expand|Select|Wrap|Line Numbers
  1. C:\apache\xampp\php\php-win.exe  "C:\Path\To\File\myphpfile.php" first second third
  2.  
And you had this in the myphpfile.php
Expand|Select|Wrap|Line Numbers
  1. <?
  2. print_r($argv);
  3. ?>
  4.  
It should output something like:
Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [0] => myphpfile.php
  4.     [1] => first
  5.     [2] => second
  6.     [3] => third
  7. )
  8.  
  9.  
Don't have a Windows machine to test this on, but it does work on Linux.
Jun 3 '08 #2
Markus
6,050 Expert 4TB
You know, I've never attempted PHP from the command line. Like OOP, it's always intimidated me.

Doesn't look to hard, actually. So I might give it a shot!
Jun 3 '08 #3
dlite922
1,584 Expert 1GB
So I might give it a shit!
I hope you don't.

A shot will be better.

Once you go OOP you never go back.

Command line is good for cron jobs. (scheduled tasks in Windows)

Maybe you need to clean up temp directories, clean up session table. FTP file somewhere, etc.

You could do it with PHP!
Jun 3 '08 #4
Markus
6,050 Expert 4TB
I hope you don't.

A shot will be better.

Once you go OOP you never go back.

Command line is good for cron jobs. (scheduled tasks in Windows)

Maybe you need to clean up temp directories, clean up session table. FTP file somewhere, etc.

You could do it with PHP!
Oh dear.

What a bad typo!
I can't even edit it!

Jeeeez.
Jun 3 '08 #5
pbmods
5,821 Expert 4TB
SuperMod to the rescue!

*sound of engine sputtering*

Oops. Forgot; my cape hasn't been reactivated yet. Well, it'll be a funny inside joke that we can't ever tell anyone else about ever.

Anyway. Here's everything you ever wanted to know and more about running PHP from the command line.

You can't simulate $_POST variables via CLI. But you could do something like this, if the code had to be runnable from both the command line and the web:

Expand|Select|Wrap|Line Numbers
  1. define('IS_CLI', php_sapi_name() == 'cli');
  2.  
  3. if( IS_CLI )
  4. {
  5.   $input =& $argv;
  6. }
  7. else
  8. {
  9.   $input =& $_POST;
  10. }
  11.  
  12. if( isset($input['report']) ) /** and so on */
  13.  
Jun 4 '08 #6
code green
1,726 Expert 1GB
Thanks Atli. The argv array, what else.
The same as C hm.
I should have realised.
So I can tag the variables to the command line.
And then use pb_mods suggestion to edit my php
Thanks a lot guys
Jun 4 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Phil Powell | last post by:
I need to find a PHP equivalent to a very familiar TCL command "subst" (see http://www.hume.com/html84/mann/subst.html ). This command will take a string and evaluate anything TCL inside of it...
9
by: Alan Silver | last post by:
Hello, I'm a bit surprised at the amount of boilerplate code required to do standard data access in .NET and was looking for a way to improve matters. In Classic ASP, I used to have a common...
4
by: Fred Weinhaus | last post by:
I would like to make a redirect and pass the POST data to the redirected page from the original page. What is the easiest way to do this? Can one do this by setting the header data in some way. If...
10
by: tony | last post by:
i'm trying to itterate through an array that contains the names of the global arrays eg: $myarray = array("\$_GET", "\$_SERVER"); and so on The problem Im having is calling a function...
6
by: admin | last post by:
Hi, I have a mysql box that has a private network ip. The old developer was running our web server on this machine but the company since retired the box and it is in a closet, still running, but...
19
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
9
by: JRough | last post by:
I tried to pass the $result from a mysql_query in a url like this line Header("Location:clm_historyXL.php?_result=".$result); but on the redirect location clm_history.php page I get an error on...
3
by: swetha123 | last post by:
hello, I don't know how to use cookies please help me in this I am using the dream weaver cs4 I designed the navigation bar to my page using dream weaver cs4 navigation bar contains...
4
anfetienne
by: anfetienne | last post by:
hi i've got this code that writes data to a text file. When i test it with a standard array eg array(1,2,3) it works perfectly fine but when i try it with $_POST i get the error message Warning:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.