I am trying to make a PHP Cli program, but there is something I do not
know what to do
If we take an example:
php5 test.php --add Hello World I am great --delete World great --sort
test.txt
I want to have an array with the commands, that look like this:
Array (
[--add] =Array('Hello', 'World', 'I', 'am', 'great'),
[--delete] =Array('World', 'great'),
['--sort'] =Array()
);
I have made 2 arrays; one with commands that takes arguments and
another with commands that takes no arguments. And in the earlier
example, the --sort command takes no argument.
Now I do not now how to make the finished array 8 2485
The87Boy wrote:
I am trying to make a PHP Cli program, but there is something I do not
know what to do
If we take an example:
php5 test.php --add Hello World I am great --delete World great --sort
test.txt
Why don't you escape the parameters?
php5 test.php --add 'Hello World I am great' --delete 'World great' \
--sort test.txt
It's standard practice, and it will ease your life when iterating through
$argv...
Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
Menos mal que la linea no da errÍ...
On Dec 28, 2:33 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
The87Boy wrote:
I am trying to make a PHP Cli program, but there is something I do not
know what to do
If we take an example:
php5 test.php --add Hello World I am great --delete World great --sort
test.txt
Why don't you escape the parameters?
php5 test.php --add 'Hello World I am great' --delete 'World great' \
--sort test.txt
It's standard practice, and it will ease your life when iterating through
$argv...
Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
Menos mal que la linea no da errÍ...
yes excatly escape the commands using " or ' and then explode by
space (" ") once you have the commands as a string
On Dec 28, 3:33 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
Why don't you escape the parameters?
php5 test.php --add 'Hello World I am great' --delete 'World great' \
--sort test.txt
It's standard practice, and it will ease your life when iterating through
$argv...
The reason why I have done it, is that it should be 5 seperate words,
and it should work with and without escapes
On Dec 28, 3:54 pm, shimmyshack <matt.fa...@gmail.comwrote:
yes excatly escape the commands using " or ' and then explode by
space (" ") once you have the commands as a string
Yes, but how do I split it up commands (the arguments that starts with
- or --)?
The87Boy wrote:
On Dec 28, 3:54 pm, shimmyshack <matt.fa...@gmail.comwrote:
>yes excatly escape the commands using " or ' and then explode by space (" ") once you have the commands as a string
Yes, but how do I split it up commands (the arguments that starts with
- or --)?
They are already in $argv !! http://php.net/manual/en/features.commandline.php
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
Proudly running Debian Linux with 2.6.22-3-amd64 kernel, KDE 3.5.8, and PHP
5.2.4-2 generating this signature.
Uptime: 16:19:29 up 36 days, 2:35, 4 users, load average: 0.64, 0.93,
0.98
On Dec 28, 4:21 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
The87Boy wrote:
On Dec 28, 3:54 pm, shimmyshack <matt.fa...@gmail.comwrote:
yes excatly escape the commands using " or ' and then explode by
space (" ") once you have the commands as a string
Yes, but how do I split it up commands (the arguments that starts with
- or --)?
They are already in $argv !!
http://php.net/manual/en/features.commandline.php
That is not the question, but how I can split up, when there is an
argument starting with - or --, so the array's key is the argument
that starts with - or -- and the array's values is the arguments, that
follows the argument
On Dec 28, 6:21 am, The87Boy <the87...@gmail.comwrote:
I am trying to make a PHP Cli program, but there is something I do not
know what to do
If we take an example:
php5 test.php --add Hello World I am great --delete World great --sort
test.txt
I want to have an array with the commands, that look like this:
Array (
[--add] =Array('Hello', 'World', 'I', 'am', 'great'),
[--delete] =Array('World', 'great'),
['--sort'] =Array()
);
How about this (untested):
$aArgs = array();
foreach ($argv as $arg) {
if (substr($arg,0,2)=="--") $aArgs[$a=$arg] = array();
else $aArgs[$a][] = $arg; }
Csaba Gabor from Vancouver
On Dec 28, 4:38 pm, Csaba Gabor <dans...@gmail.comwrote:
On Dec 28, 6:21 am, The87Boy <the87...@gmail.comwrote:
I am trying to make a PHP Cli program, but there is something I do not
know what to do
If we take an example:
php5 test.php --add Hello World I am great --delete World great --sort
test.txt
I want to have an array with the commands, that look like this:
Array (
[--add] =Array('Hello', 'World', 'I', 'am', 'great'),
[--delete] =Array('World', 'great'),
['--sort'] =Array()
);
How about this (untested):
$aArgs = array();
foreach ($argv as $arg) {
if (substr($arg,0,2)=="--") $aArgs[$a=$arg] = array();
else $aArgs[$a][] = $arg; }
You are right, but I thought, I could validate if the argument
starting with - or --, was in the array with arguments This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chuck Anderson |
last post by:
I have a function with 7 inputs. The last three have default values.
I want to call that function specifying the first four, skip two and
then specify the last.
I thought I could write this...
|
by: Matt Eberts |
last post by:
Sorry, bad title. Anyway, is there a way to pass the arguments to an object
instantiated via a constructor using the arguments object and have it
expanded, so to speak, so that it doesn't appear as...
|
by: Melkor Ainur |
last post by:
Hello,
I'm attempting to build an interpreter for a pascal-like language.
Currently, I don't generate any assembly. Instead, I just build an
abstract syntax tree representing what I've parsed...
|
by: dragoncoder |
last post by:
Consider the following code.
#include <stdio.h>
int main()
{
int i =1;
printf("%d ,%d ,%d\n",i,++i,i++);
return 0;
}
|
by: Telmo Costa |
last post by:
Hi. I have the following code:
--------------------------------------
function Tunnel() {
//arguments(???);
}
function Sum() {
var sum = 0;
for (i=0; i<arguments.length; i++) sum +=...
|
by: Csaba Gabor |
last post by:
Inside a function, I'd like to know the call stack. By this I mean
that I'd like to know the function that called this one, that one's
caller and so on.
So I thought to do:
<script...
|
by: sfeher |
last post by:
Hi All,
Is there a way to preserve the arguments across functions?
I have:
<script>
function myFirstFunction()
{
// arguments = 'param1'
|
by: Pacific Fox |
last post by:
Hi all,
haven't posted to this group before, but got an issue I can't work
out... and hoping to get some help here ;-)
I've got a base object that works fine with named arguments when called...
|
by: VK |
last post by:
I was getting this effect N times but each time I was in rush to just
make it work, and later I coudn't recall anymore what was the original
state I was working around. This time I nailed the...
|
by: ADezii |
last post by:
When a call is made to a Sub or Function Procedure, you can supply Arguments in the exact order they appear in the Procedure's definition, or you can supply them in any position by name. To...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shćllîpôpď 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |