Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17060 > unrolled thread

How to know the last arg in a series

Started bybit-naughty@hotmail.com
First post2016-09-18 23:51 -0700
Last post2016-09-22 17:08 +0200
Articles 13 — 8 participants

Back to article view | Back to comp.lang.php


Contents

  How to know the last arg in a series bit-naughty@hotmail.com - 2016-09-18 23:51 -0700
    Re: How to know the last arg in a series "R.Wieser" <address@not.available> - 2016-09-19 10:00 +0200
      Re: How to know the last arg in a series bit-naughty@hotmail.com - 2016-09-21 23:54 -0700
        Re: How to know the last arg in a series "R.Wieser" <address@not.available> - 2016-09-22 09:03 +0200
    Re: How to know the last arg in a series bill <william@TechServSys.com> - 2016-09-19 07:05 -0400
    Re: How to know the last arg in a series Jerry Stuckle <jstucklex@attglobal.net> - 2016-09-19 08:45 -0400
      Re: How to know the last arg in a series Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-19 14:10 +0100
        Re: How to know the last arg in a series Jerry Stuckle <jstucklex@attglobal.net> - 2016-09-19 10:55 -0400
    Re: How to know the last arg in a series "J.O. Aho" <user@example.net> - 2016-09-19 18:53 +0200
    Re: How to know the last arg in a series Arno Welzel <usenet@arnowelzel.de> - 2016-09-19 21:38 +0200
    Re: How to know the last arg in a series bit-naughty@hotmail.com - 2016-09-22 00:02 -0700
      Re: How to know the last arg in a series Luuk <luuk@invalid.lan> - 2016-09-22 17:07 +0200
        Re: How to know the last arg in a series Luuk <luuk@invalid.lan> - 2016-09-22 17:08 +0200

#17060 — How to know the last arg in a series

Frombit-naughty@hotmail.com
Date2016-09-18 23:51 -0700
SubjectHow to know the last arg in a series
Message-ID<1b8fa718-fcde-4e92-9ad3-cc69e41f5a0b@googlegroups.com>
If I have a page where there are args like "arg1=2&arg2=93&arg3=112", and so on, but there is No Limit to how many "arg"s there can be, how do I find out which one the last arg is ("arg3" in the above case)?


Thanks.

[toc] | [next] | [standalone]


#17061

From"R.Wieser" <address@not.available>
Date2016-09-19 10:00 +0200
Message-ID<57df9b00$0$911$e4fe514c@news.xs4all.nl>
In reply to#17060
bit-naughty,

> but there is No Limit to how many "arg"s there can be

You will need to explain that a bit more: which limit are you talking about
?  The one the HTTP protocol sets to it(1), or the ammount you are defining
in your webpage(2).

1) There is a limit, and its not the number of arguments, but the total size
of the URL + arguments + EOL is about 2048 bytes.

Ofcourse, you can also send those arguments using the POST method, which
effectivily removes that size constraint (results are than stored in the
$_POST array).

2a) If you want to find the last argument onthat raw line than simply do a
strrev for the "&" character, and take everything rignt of it.

2b) If you want to take it outof the $_GET/$_POST array than you could loop
thru all the keys in there, remove the first three chars ("arg"), convert
the remaining to an integer and remember the largest value found.
After that prepend the "arg" to that value and voilla, there is your last
argument.

2c) When you assume that the arguments are stored in that $_GET/$_POST array
in the same order as they appear as arguments in the URL than it becomes
even easier: just get the last key outof the array. :-)

... assuming that all arguments are provided sequentially ofcourse.

But why would you need to find it ?    If you loop thru all elements of that
_GET/$_POST array you will go thru all the provided arguments anyway (in
other words, is there something important going on with that last argument
?).

Regards,
Rudy Wieser

P.s.
I have not seen you respond to the replies to your origional question.  Did
any of them solve your problem (make it a bit more clear to what happens) ?
If so, it would be nice when you would mention it.


-- Origional message:
<bit-naughty@hotmail.com> schreef in berichtnieuws
1b8fa718-fcde-4e92-9ad3-cc69e41f5a0b@googlegroups.com...
> If I have a page where there are args like "arg1=2&arg2=93&arg3=112", and
so on, but there is No Limit to how many "arg"s there can be, how do I find
out which one the last arg is ("arg3" in the above case)?
>
>
> Thanks.

[toc] | [prev] | [next] | [standalone]


#17085

Frombit-naughty@hotmail.com
Date2016-09-21 23:54 -0700
Message-ID<d26c5e3b-187f-46dd-9146-320b4dc812dd@googlegroups.com>
In reply to#17061
On Monday, September 19, 2016 at 1:30:10 PM UTC+5:30, R.Wieser wrote:

> P.s.
> I have not seen you respond to the replies to your origional question.  Did
> any of them solve your problem (make it a bit more clear to what happens) ?
> If so, it would be nice when you would mention it.


Sorry mate, which question did you mean? This thread, or one of my others? This one I'm looking at just now....? 


OK everyone, I'm going to have to take some time to go through all that's been said. Just give me a day or two :)

[toc] | [prev] | [next] | [standalone]


#17087

From"R.Wieser" <address@not.available>
Date2016-09-22 09:03 +0200
Message-ID<57e38244$0$9830$e4fe514c@news.xs4all.nl>
In reply to#17085
bit-naughty,

> Sorry mate, which question did you mean? This thread, or one
> of my others? This one I'm looking at just now....?

I see I mixed up two threads.   My apologies.

I was referring to the "HTTPS data in a form" thread.  Several people have
responded, but I do not see any further post(s) from you.

Regards,
Rudy Wieser


-- Origional message:
<bit-naughty@hotmail.com> schreef in berichtnieuws
d26c5e3b-187f-46dd-9146-320b4dc812dd@googlegroups.com...
> On Monday, September 19, 2016 at 1:30:10 PM UTC+5:30, R.Wieser wrote:
>
> > P.s.
> > I have not seen you respond to the replies to your origional question.
Did
> > any of them solve your problem (make it a bit more clear to what
happens) ?
> > If so, it would be nice when you would mention it.
>
>
> Sorry mate, which question did you mean? This thread, or one of my others?
This one I'm looking at just now....?
>
>
> OK everyone, I'm going to have to take some time to go through all that's
been said. Just give me a day or two :)

[toc] | [prev] | [next] | [standalone]


#17062

Frombill <william@TechServSys.com>
Date2016-09-19 07:05 -0400
Message-ID<nrogpo$bql$2@gioia.aioe.org>
In reply to#17060
On 9/19/2016 2:51 AM, bit-naughty@hotmail.com wrote:
> If I have a page where there are args like "arg1=2&arg2=93&arg3=112", and

so on, but there is No Limit to how many "arg"s

there can be, how do I find out which one the last arg is ("arg3" 
in the above case)?
>
>
> Thanks.
>
the answer depends on why you want to know what the last arg is.
If you want to know so you can extract data, foreach will do it 
automagically
-bill

[toc] | [prev] | [next] | [standalone]


#17063

FromJerry Stuckle <jstucklex@attglobal.net>
Date2016-09-19 08:45 -0400
Message-ID<nromm0$bg8$1@jstuckle.eternal-september.org>
In reply to#17060
On 9/19/2016 2:51 AM, bit-naughty@hotmail.com wrote:
> If I have a page where there are args like "arg1=2&arg2=93&arg3=112", and so on, but there is No Limit to how many "arg"s there can be, how do I find out which one the last arg is ("arg3" in the above case)?
> 
> 
> Thanks.
> 

Rudy has some good comments, but I wonder about your page layout.  In
your html, you probably have something like:

<input type="text" name="arg1" ...>
<input type="text" name="arg2" ...>

However, since these seem to be related, a better way could be something
like

<input type="text" name="arg[]" ...>
<input type="text" name="arg[]" ...>

This will create the array $_GET[arg[0]], GET[arg[1]], etc. and you can
easily use the array functions to get the size and process the members.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17064

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-09-19 14:10 +0100
Message-ID<87poo0hw6f.fsf@bsb.me.uk>
In reply to#17063
Jerry Stuckle <jstucklex@attglobal.net> writes:
<snip>
> However, since these seem to be related, a better way could be something
> like
>
> <input type="text" name="arg[]" ...>
> <input type="text" name="arg[]" ...>
>
> This will create the array $_GET[arg[0]], GET[arg[1]], etc. and you can
> easily use the array functions to get the size and process the
> members.

Something's gone wrong with that syntax.  $_GET['arg'] will be an array,
so you can access $_GET['arg'][0], $_GET['arg'][1] and so on, or, as you
say, use other array operations on the value of $_GET['arg'].

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#17065

FromJerry Stuckle <jstucklex@attglobal.net>
Date2016-09-19 10:55 -0400
Message-ID<nrou9f$6lp$1@jstuckle.eternal-september.org>
In reply to#17064
On 9/19/2016 9:10 AM, Ben Bacarisse wrote:
> Jerry Stuckle <jstucklex@attglobal.net> writes:
> <snip>
>> However, since these seem to be related, a better way could be something
>> like
>>
>> <input type="text" name="arg[]" ...>
>> <input type="text" name="arg[]" ...>
>>
>> This will create the array $_GET[arg[0]], GET[arg[1]], etc. and you can
>> easily use the array functions to get the size and process the
>> members.
> 
> Something's gone wrong with that syntax.  $_GET['arg'] will be an array,
> so you can access $_GET['arg'][0], $_GET['arg'][1] and so on, or, as you
> say, use other array operations on the value of $_GET['arg'].
> 

Sorry, you're correct.  Comes from trying to hurry my response too much :<

Thanks for the correction.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17066

From"J.O. Aho" <user@example.net>
Date2016-09-19 18:53 +0200
Message-ID<e4ajfpF976pU1@mid.individual.net>
In reply to#17060
On 09/19/2016 08:51 AM, bit-naughty@hotmail.com wrote:
> If I have a page where there are args like "arg1=2&arg2=93&arg3=112", and so on, but there is No Limit to how many "arg"s there can be, how do I find out which one the last arg is ("arg3" in the above case)?
> 
> 
> Thanks.
> 

With the huge amount of information I just assumed that you wanted to
play with the QUERY_REQUEST _SERVER value. This solution do not use
regexp, which would be a better solution:

<?php
if(!empty($_SERVER['QUERY_STRING'])) {
    $array = explode('&', $_SERVER['QUERY_STRING']);
    if(strpos($array[count($array) -1], '=')!==false) {
        list($key, $value) = explode('=', $array[count($array) -1]);

        echo "The key is '${key}'\n";
        echo "The valu is '${value}'\n";
    } else {
        echo "Didn't manage to find any values in the query string\n";
    }
} else {
    echo "No get values was sent\n";
}
?>


If it was something else you wanted, then please describe your problem
in detail, so that we can understand what you are trying to do.

-- 

 //Aho

[toc] | [prev] | [next] | [standalone]


#17068

FromArno Welzel <usenet@arnowelzel.de>
Date2016-09-19 21:38 +0200
Message-ID<0ba934ff-b771-06bc-9ef9-b79aa538681e@arnowelzel.de>
In reply to#17060
bit-naughty@hotmail.com schrieb am 2016-09-19 um 08:51:

> If I have a page where there are args like "arg1=2&arg2=93&arg3=112",
> and so on, but there is No Limit to how many "arg"s there can be, how
> do I find out which one the last arg is ("arg3" in the above case)?

By checking the last entry of the $_GET array.


-- 
Arno Welzel
https://arnowelzel.de
http://de-rec-fahrrad.de
http://fahrradzukunft.de

[toc] | [prev] | [next] | [standalone]


#17086

Frombit-naughty@hotmail.com
Date2016-09-22 00:02 -0700
Message-ID<a718f09c-ddb8-4f97-a397-8ca4ef09178d@googlegroups.com>
In reply to#17060
Umm OK, I just wann say:
I want to know the last one because there is potentially no limit to the amount of args there can be - imagine a form where a Saudi Arabian user is asked "What are the names of all your wives?", together with a "NEXT" button on the form (somehow) that'll open up another input box (with potentially no limit to the number of input boxes that can be opened up!). So, if the guy has 20 wives, he will enter the names of all 20, if he has 30 then 30, and so on...

THOSE args have to be given to the SELECT in the MYSQL database. That's what I''m trying to achieve.

*How* to code the form - now THAT's something I'm trying to find out on the Javascript group :)

[toc] | [prev] | [next] | [standalone]


#17088

FromLuuk <luuk@invalid.lan>
Date2016-09-22 17:07 +0200
Message-ID<57e3f3a2$0$905$e4fe514c@news.xs4all.nl>
In reply to#17086
On 22-09-16 09:02, bit-naughty@hotmail.com wrote:
> Umm OK, I just wann say:
> I want to know the last one because there is potentially no limit to the amount of args there can be - imagine a form where a Saudi Arabian user is asked "What are the names of all your wives?", together with a "NEXT" button on the form (somehow) that'll open up another input box (with potentially no limit to the number of input boxes that can be opened up!). So, if the guy has 20 wives, he will enter the names of all 20, if he has 30 then 30, and so on...
>
> THOSE args have to be given to the SELECT in the MYSQL database. That's what I''m trying to achieve.
>
> *How* to code the form - now THAT's something I'm trying to find out on the Javascript group :)
>

<?php
foreach($_GET as $key=>$value) {
         print $key;
         print ": ";
         print $value;
         print "<br>";
}
?>

a request like this:
http://localhost/test.php?a=1&b=2&c=3

should output:
a: 1
b: 2
c: 3

[toc] | [prev] | [next] | [standalone]


#17089

FromLuuk <luuk@invalid.lan>
Date2016-09-22 17:08 +0200
Message-ID<57e3f3d0$0$905$e4fe514c@news.xs4all.nl>
In reply to#17088
On 22-09-16 17:07, Luuk wrote:
> On 22-09-16 09:02, bit-naughty@hotmail.com wrote:
>> Umm OK, I just wann say:
>> I want to know the last one because there is potentially no limit to
>> the amount of args there can be - imagine a form where a Saudi Arabian
>> user is asked "What are the names of all your wives?", together with a
>> "NEXT" button on the form (somehow) that'll open up another input box
>> (with potentially no limit to the number of input boxes that can be
>> opened up!). So, if the guy has 20 wives, he will enter the names of
>> all 20, if he has 30 then 30, and so on...
>>
>> THOSE args have to be given to the SELECT in the MYSQL database.
>> That's what I''m trying to achieve.
>>
>> *How* to code the form - now THAT's something I'm trying to find out
>> on the Javascript group :)
>>
>
> <?php
> foreach($_GET as $key=>$value) {
>         print $key;
>         print ": ";
>         print $value;
>         print "<br>";
> }
> ?>
>
> a request like this:
> http://localhost/test.php?a=1&b=2&c=3
>
> should output:
> a: 1
> b: 2
> c: 3

Therefore there's no need to know the last arg..... (as stated before by 
someone else)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web