PHP addslashes to an Array

This is for a solution for adding slashes to a $_POST array when you don’t know if magic quotes is turned on.

 

array_walk($_POST, 'reslash_multi');

function reslash_multi(&$val,$key) 
{
   if (is_array($val)) array_walk($val,'reslash_multi',$new);
   else {
      $val = reslash($val);
   }
}

function reslash($string)
{
   if (!get_magic_quotes_gpc())$string = addslashes($string);
   return $string;
}
×

Comments are closed.