Forum Moderators: coopster
I have the following function which is supposed to strip all whitespaces & replace any occurence of ; with ";" on Post Variables but it does not appear to be working.
Any ideas what could be wrong?
Thanx
PeterC
validate();
function validate()
{
global $HTTP_POST_VARS;
foreach($HTTP_POST_VARS as $key=>$val)
{
$val = trim(str_replace(";", "\";\"",$val));
}
}
One more thing, can I use the fornext to assign array variables to single variables i.e.:
foreach($HTTP_POST_VARS as $key=>$val)
{
$val = trim(str_replace(";", "\";\"",$val));
"$".$key = $val
}
What I want is a series of seperate valiables created in the foreach loop without need to specify them individually like this;
$name = $val['name']
$address = $val['address']
You want something like this perhaps (Sorry, but I can't workwithout my own indenting):
Oh, and you should use $_POST instead of $HTTP_POST_VARS for forwards compatibility to PHP5, which I use.
function validate(){
global $HTTP_POST_VARS;
$validatedVars=Array();
foreach($HTTP_POST_VARS as $key=>$val){
$validatedVars[$key]=trim(str_replace(";", "\";\"",$val));
}
return $validatedVars;
}
foreach($_POST as $key => $val) {
$_POST[$key] = trim(str_replace(";", "\";\"",$val));
}
extract [php.net]($_POST);