Forum Moderators: coopster
function cleaner($data)
{
if(is_array($data))
{
$ret = array();
foreach($data as $key=>$value)
{
$ret[$key] = cleaner($value);
}
return $ret;
}
else
{
if(!is_numeric($data))
{
if(get_magic_quotes_gpc())
{
$data = stripslashes($data);
}
$data = mysql_real_escape_string($data);
}
return $data;
}
}
// declare the variables and clean
$name = $clean['name'];
$email_address = $clean['from'];
function CleanData($dataBaseConn){
//Use the callback function in array map to make things efficient :)
$_POST = array_map('strip_tags', $_POST);
$_POST = array_map('trim', $_POST);
//use this function ONLY if there is a valid connection handle about, otherwise it won't function :)
if($dataBaseConn){
$_POST = array_map('mysql_real_escape_string', $_POST);
}
//Check magic quotes is on, if so use it, again, depending on context of data
//This may not be the best place to use this, might as well just use this
//just before database query....
if(get_magic_quotes_gpc())
{
$_POST = array_map('stripslashes',$_POST);
}
//Return data - cleansed :)
return $_POST;
}
if(!preg_match('/^[\d]+$/', $_POST['key_name'])){
//not numerical data in here :)
}