473,385 Members | 1,907 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,385 software developers and data experts.

PHP.exe interpreter and sending variables

Question, I am testing php scripts through the console app(php.exe) how
can I send form variables to it? Or can I? Can I just fill in
variables into _POST['val'] for example.

--
Ramza from Atlanta
http://www.newspiritcompany.com
Aug 11 '05 #1
5 2245
*** Ramza Brown wrote/escribió (Thu, 11 Aug 2005 08:04:21 -0400):
Question, I am testing php scripts through the console app(php.exe) how
can I send form variables to it? Or can I? Can I just fill in
variables into _POST['val'] for example.


POST is a method of the HTTP protocol, protocol that is obviously not used
when executing a script though the command line. If your input comes from
forms, you should probably write an intermediate script that runs through a
web server and convert the input in something a command line tool can reach
(database, file, command-line arguments...).

Yes, $_POST is a writeable array but, where are you getting the values to
fill into it?

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Aug 11 '05 #2
Check out $argc[] and $argv[]:

http://www.php.net/reserved.variables

Aug 11 '05 #3
ZeldorBlat wrote:
Check out $argc[] and $argv[]:

http://www.php.net/reserved.variables

Hmm, this looks interesting, can you translate that? For what I want.

--
Ramza from Atlanta
http://www.newspiritcompany.com
Aug 11 '05 #4
One option would be to pass each desired form variable as a key=value
pair, then have a method populate $_POST from $argv. So, if you had
three post variables called var1, var2, and var3, you would call your
script from the command line as follows:

php myscript.php var1=val1 var2=val2 var3=val3

Then, inside your script, do something like this:

for($i = 1; $i < $argc; $i++) { //the first one is the script name
$param = explode('=', $argv[$i]);
$_POST[$param[0]] = $params[1];
}

Another alternative would be to pass a single command line argument
containing something like a URL query string. So, in the above example
you would use the following on the command line:

php myscript.php var1=val1&var2=val2&var3=val3

Then, inside your script, try something like:

$params = array();
parse_str($argv[1], $params);
foreach($params as $key => $val)
$_POST[$key] = $val;

Aug 11 '05 #5
ZeldorBlat wrote:
One option would be to pass each desired form variable as a key=value
pair, then have a method populate $_POST from $argv. So, if you had
three post variables called var1, var2, and var3, you would call your
script from the command line as follows:

php myscript.php var1=val1 var2=val2 var3=val3

Then, inside your script, do something like this:

for($i = 1; $i < $argc; $i++) { //the first one is the script name
$param = explode('=', $argv[$i]);
$_POST[$param[0]] = $params[1];
}

Another alternative would be to pass a single command line argument
containing something like a URL query string. So, in the above example
you would use the following on the command line:

php myscript.php var1=val1&var2=val2&var3=val3

Then, inside your script, try something like:

$params = array();
parse_str($argv[1], $params);
foreach($params as $key => $val)
$_POST[$key] = $val;

Gracias, thanks.
--
Ramza from Atlanta
http://www.newspiritcompany.com
Aug 11 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to...
5
by: Rafal Kleger-Rudomin | last post by:
Hello, I'm looking for a command to reset interpreter's environment i.e. unload all modules, delete variables etc. Regards, Rafal
70
by: hanch | last post by:
Hi, I'm looking for a comfortable IDE for c++ with c++ interpreter, so i'd be able to execute c scripts and alter code during debug. thnks
6
by: wooks | last post by:
Sorry if this is very basic. I have bought a Functional Programming book that uses the language Hope. I have managed to locate and extract Ross Pattersons hope interpreter from...
12
by: ozbear | last post by:
If one were writing a C interpreter, is there anything in the standard standard that requires the sizeof operator to yield the same value for two different variables of the same type? Let's...
3
by: Robin Becker | last post by:
As part of some django usage I need to get some ReportLab C extensions into a state where they can be safely used with mod_python. Unfortunately we have C code that seems incompatible with...
3
by: R. Bernstein | last post by:
The next release of pydb will have the ability to go into ipython from inside the debugger. Sort of like how in ruby-debug you can go into irb :-) For ipython, this can be done pretty simply;...
40
by: castironpi | last post by:
I'm curious about some of the details of the internals of the Python interpreter: I understand C from a hardware perspective. x= y+ 1; Move value from place y into a register Add 1 to the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.