Connecting Tech Pros Worldwide Help | Site Map

The $_POST array

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 10th, 2005, 10:25 AM
Jørn Dahl-Stamnes
Guest
 
Posts: n/a
Default The $_POST array

I got the following code:

reset ($_POST);
while (list($key,$val) = each($_POST))
{
echo "$key => $val\n";
}

But this prints out nothing. If I replace the code above with:


print_r ($_POST);

I can see the content of the $_POST array. Why?

--
Jørn Dahl-Stamnes
http://www.dahl-stamnes.net/dahls/

  #2  
Old November 10th, 2005, 11:35 AM
IWT
Guest
 
Posts: n/a
Default Re: The $_POST array


Jørn Dahl-Stamnes wrote:[color=blue]
> I got the following code:
>
> reset ($_POST);
> while (list($key,$val) = each($_POST))
> {
> echo "$key => $val\n";
> }
>
> But this prints out nothing. If I replace the code above with:
>
>
> print_r ($_POST);
>
> I can see the content of the $_POST array. Why?[/color]

Try this:

foreach($_POST as $key => $value)
echo $key."=".$value;

  #3  
Old November 10th, 2005, 01:15 PM
Jørn Dahl-Stamnes
Guest
 
Posts: n/a
Default Re: The $_POST array

IWT wrote:
[color=blue]
>
> Jørn Dahl-Stamnes wrote:[color=green]
>> I got the following code:
>>
>> reset ($_POST);
>> while (list($key,$val) = each($_POST))
>> {
>> echo "$key => $val\n";
>> }
>>
>> But this prints out nothing. If I replace the code above with:
>>
>>
>> print_r ($_POST);
>>
>> I can see the content of the $_POST array. Why?[/color]
>
> Try this:
>
> foreach($_POST as $key => $value)
> echo $key."=".$value;[/color]

Tried that too. Still no output...

--
Jørn Dahl-Stamnes
http://www.dahl-stamnes.net/dahls/
  #4  
Old November 10th, 2005, 01:25 PM
Ewoud Dronkert
Guest
 
Posts: n/a
Default Re: The $_POST array

Jørn Dahl-Stamnes wrote:[color=blue]
> I got the following code:
>
> reset ($_POST);
> while (list($key,$val) = each($_POST))
> {
> echo "$key => $val\n";
> }
>
> But this prints out nothing. If I replace the code above with:
>
>
> print_r ($_POST);
>
> I can see the content of the $_POST array. Why?[/color]

Can't think of anything but:
- it's a bug in your php version...,
- echo is buffered and/or redirected and print_r is not,
- "list" or "each" are redefined as constants earlier,
- the contents of $key or $val are preventing output.

If the last point, try using htmlspecialchars().

--
E. Dronkert
  #5  
Old November 10th, 2005, 09:05 PM
Jørn Dahl-Stamnes
Guest
 
Posts: n/a
Default Re: The $_POST array

Ewoud Dronkert wrote:
[color=blue]
> Jørn Dahl-Stamnes wrote:[color=green]
>> I got the following code:
>>
>> reset ($_POST);
>> while (list($key,$val) = each($_POST))
>> {
>> echo "$key => $val\n";
>> }
>>
>> But this prints out nothing. If I replace the code above with:
>>
>>
>> print_r ($_POST);
>>
>> I can see the content of the $_POST array. Why?[/color]
>
> Can't think of anything but:
> - it's a bug in your php version...,
> - echo is buffered and/or redirected and print_r is not,
> - "list" or "each" are redefined as constants earlier,
> - the contents of $key or $val are preventing output.[/color]

Seems like a bug to me. I tried this:

$text = print_r ($_POST,true);
echo $text;

and it worked OK. So I'm able to get around this possible bug.

--
Jørn Dahl-Stamnes
http://www.dahl-stamnes.net/dahls/
  #6  
Old November 10th, 2005, 09:05 PM
Justin Koivisto
Guest
 
Posts: n/a
Default Re: The $_POST array

Jørn Dahl-Stamnes wrote:[color=blue]
> I got the following code:
>
> reset ($_POST);
> while (list($key,$val) = each($_POST))
> {
> echo "$key => $val\n";
> }
>
> But this prints out nothing. If I replace the code above with:
>
>
> print_r ($_POST);
>
> I can see the content of the $_POST array. Why?
>[/color]

Try this:

$ar=$_POST;
while (list($key,$val) = each($ar))
{
echo "$key => $val\n";
}

IIRC, older PHP versions had a problem with using the each function (and
the foreach) with any of the superglobal arrays...

--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
  #7  
Old November 10th, 2005, 09:15 PM
Ewoud Dronkert
Guest
 
Posts: n/a
Default Re: The $_POST array

Justin Koivisto wrote:[color=blue]
> IIRC, older PHP versions had a problem with using the each function (and
> the foreach) with any of the superglobal arrays...[/color]

I thought that might be the case, but couldn't find anything with some
quick searches earlier (googled "php list each superglobal" and looked at
the comments at php.net/each).

--
E. Dronkert
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.