Re: formatting $HTTP_POST_VARS

From: Date: Thu, 19 Oct 2000 22:41:58 +0000
Subject: Re: formatting $HTTP_POST_VARS
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-21293@lists.php.net to get a copy of this message
On Thu, 19 Oct 2000, Jerry Lake wrote: > I'm trying to format the > results of a form to a webpage > in a nice looking fashion > and I cant seem to get it to > look nice or to work most of the time > > here is what I'm trying > any ideas? I think perhaps I've > hit one of those learning plateaus...? > > /****************************/ > reset ($HTTP_POST_VARS); > while (list ($key, $val) = each ($HTTP_POST_VARS)) > { > $longest = 0; > for($i=0; $i<count($key); $i++) > { > if(strlen($key[$i]) > strlen($key[$longest])) $longest = $i; > } > $length = strlen($key[$longest]); > > for($i=0; $i<count($key); $i++) > { > $padding = $length - strlen($key[$i]);; > for($j=0; $j<$padding; $j++) > { > $key[$i] .= '.'; > } > $key[$i] .= '..: '.$val[$i]; > } > $echo $key[$i] .= '..: '.$val[$i]; > } > /***************************/ > Why don't you just use a table? function show_table($Data) { reset($Data); echo '<TABLE>'; while (list($Name, $Value) = each($Data)) { echo "<TR><TD>$Name</TD><TD>"; if (is_array($Value)) { show_table($Value); } else { echo $Value; } echo '</TD></TR>'; } echo '</TABLE>'; } show_table($HTTP_POST_VARS); Using recursion this way will allow for some form values to be arrays. Of course, some browsers will choke if you have deeply nested tables, but usually that won't be the case. You can add whatever formatting you want to the TABLE, TD and TR tags. If you passed a 'depth' parameter in the function call allow with the $Data array, and incremented $depth in each call, you could even change the formatting depending on how deepply-nested your tables were. Standard untested code caveats apply. -steve ........................................................... . Steve Edberg sbedberg@ucdavis.edu . . Computer Consultant University of California, Davis . . (530)754-9127 . ...........................................................

« previous php.general (#21293) next »