Hi!
I am writing a class which needs to take all query string variables as an array ($HTTP_GET_VARS or $HTTP_POST_VARS), loop through the array and unset some variables I do not need:
$query_var_container = 'HTTP'.strtoupper($this->getMethod()).'VARS';
global $$query_var_container;
$query_vars = $$query_var_container;
// strip control variables from query string
foreach ($this->query_vars as $v)
{
unset($query_vars[$v]);
}
After that I need to write these variables either to the end of a link or to the VALUE attribute of the HIDDEN form element.
-- for HIDDEN elements --
$hidden = '';
foreach ($query_vars as $k=>$v)
{
$hidden .= "<input type=\"hidden\" name=\"$k\" value=\"".addslashes($v)."\">\n";
}
-- for a URL --
$qr = '';
foreach ($query_vars as $k=>$v)
{
$qr .= $k.'='.urlencode($v).'&';
}
if (!empty($qr)) $qr = substr($qr, 0, -1);
I don't quite understand what function to apply to each value taken from the query array. Is it urlencode() alone? Or also addslashes()? Some other function? I read in the PHP.net comments for stripslashes() that urlencode() should be coupled with stripslashes() to do correct conversion for HIDDEN elements' value attribute.
Also, do I have to urlencode() the $k in the above scripts?
Thanks a lot in advance,
Stanislav