renaming form posted variable names
| From: | David Minor | Date: | Sat, 31 Mar 2001 04:48:58 +0000 |
| Subject: | renaming form posted variable names | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-46433@lists.php.net to get a copy of this message | ||
I've got a logic problem that I just can't think through. I'm hoping that
you can help me find a better way to do this. I need a function that will
iterate through $HTTP_POST_VARS looking for variable names with a predefined
suffix ($example_post). Then I want to save the value of this var in a
variable named $example. The code that I already have successfully does the
iteration and selection of vars. What I can't do is make the new var
($example) accessible to the rest of the script. How should I do this?
<PRE>
function do_each($passed_array) {
global ${$tmp_var_name};
if (substr($passed_array[0],-5) == "_post") {
$tmp_var_name = substr($passed_array[0],0,-5);
${$tmp_var_name} = $passed_array[1];
return(${$tmp_var_name});
}
}
function conv_vars($input) {
global ${$tmp_var_name};
if (IsSet($input)) {
while ($each_array = each($input)) {
if (is_array($each_array[1])) // if nested array
conv_vars($each_array[1]); // pass to self
else
$new_var_value = do_each($each_array);
}
}
}
conv_vars($HTTP_POST_VARS);
</PRE>
Thanks in advance for the help. I learn so much from this list!
dm