Matching GET values...

This is a discussion on Matching GET values... within the PHP Language forums, part of the PHP Programming Forums category; All, I am trying to pass each GET variable to a function and check if it was expected. For example, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-29-2004
Dimension7
 
Posts: n/a
Default Matching GET values...

All,
I am trying to pass each GET variable to a function and check if it was
expected.
For example, here is a sample link:

index.php?name=modname&file=filename&func=1

the problem is, instead of returning:
match
match
match

it returns:

match
no match
no match
no match
match
no match
no match
no match
match

I know the problem is something with the =each, because it is evaluating
each item against each other, I just don't know how to fix it.

function bmcheck ($bmc, $g)
{
$bmchk = 0;
while (list ($key, $val) = each ($bmc)) {
if ($val == $g) {
echo "match";
echo "<br>";
} else {
echo "no match";
echo "<br>";
}
}
}

$bmc = array("name","file","func");
foreach ($_GET as $gvalue => $g) {
bmcheck($bmc, $gvalue);
}

Basically, when I'm done, if something like this was passed:
index.php?name=modname&file=filename&func=1&bad=no tsupposedtobehere
then I would see 3 "matches" and 1 "no match" for the "bad" parameter.

I hope this makes some sense =)
Thanks.


Reply With Quote
  #2 (permalink)  
Old 04-29-2004
Pedro Graca
 
Posts: n/a
Default Re: Matching GET values...

Dimension7 wrote:
> All,
> I am trying to pass each GET variable to a function and check if it was
> expected.
> For example, here is a sample link:
>
> index.php?name=modname&file=filename&func=1

(...)
> I know the problem is something with the =each, because it is evaluating
> each item against each other, I just don't know how to fix it.
>
> function bmcheck ($bmc, $g)
> {
> $bmchk = 0;


What's this $bmchk for ? You do not use at all!
Well ... I do :)

> while (list ($key, $val) = each ($bmc)) {
> if ($val == $g) {

$bmchk = 1;
}

$bmchk was initialized to 0 before the while() and will only get set to
1 if at least one of the $bmc keys matches the $g parameter.

#> echo "match";
#> echo "<br>";
#> } else {
#> echo "no match";
#> echo "<br>";
#> }
> }


Now all keys have been checked and $bmchk is either 0 (no matches) or 1
(1 or more matches)

if ($bmchk) echo "match<br>";
else echo "no match<br>";

> }
>
> $bmc = array("name","file","func");
> foreach ($_GET as $gvalue => $g) {
> bmcheck($bmc, $gvalue);
> }
>
> Basically, when I'm done, if something like this was passed:
> index.php?name=modname&file=filename&func=1&bad=no tsupposedtobehere
> then I would see 3 "matches" and 1 "no match" for the "bad" parameter.
>
> I hope this makes some sense =)


I hope my post makes sense :-)

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Reply With Quote
  #3 (permalink)  
Old 04-29-2004
Daniel Tryba
 
Posts: n/a
Default Re: Matching GET values...

Dimension7 <dimension@seven.com> wrote:
> $bmc = array("name","file","func");
> foreach ($_GET as $gvalue => $g) {
> bmcheck($bmc, $gvalue);
> }
>
> Basically, when I'm done, if something like this was passed:
> index.php?name=modname&file=filename&func=1&bad=no tsupposedtobehere
> then I would see 3 "matches" and 1 "no match" for the "bad" parameter.


With bmcheck you are trying to reinvent array_key_exists(), sounds kind
of silly to me :)

function bmcheck($arr,$key)
{
if(array_key_exists($key,$arr))
{
echo "match";
}
else
{
echo "nomatch";
}
}


--

Daniel Tryba

Reply With Quote
  #4 (permalink)  
Old 04-30-2004
Kelly Thompson
 
Posts: n/a
Default Re: Matching GET values...

On 29 Apr 2004 08:37:27 GMT
Pedro Graca <hexkid@hotpop.com> wrote:

> Dimension7 wrote:
> > All,
> > I am trying to pass each GET variable to a function and check if
> > it was expected.
> > For example, here is a sample link:
> >
> > index.php?name=modname&file=filename&func=1

> (...)
> > I know the problem is something with the =each, because it is
> > evaluating each item against each other, I just don't know how to
> > fix it.
> >
> > function bmcheck ($bmc, $g)
> > {
> > $bmchk = 0;

>
> What's this $bmchk for ? You do not use at all!
> Well ... I do :)
>
> > while (list ($key, $val) = each ($bmc)) {
> > if ($val == $g) {

> $bmchk = 1;


break;

> }


You found what you're looking for, just stop then.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:46 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0