If I use the function with an array, I always get the same thing back. This is the first time that I try to create a recursive function, so it probably has something to do with that.
Anyway, the function:
Code: Select all
/**
* @return mixed
* @param mixed $data
* @desc Clear a variable from evil code. If it's an array, clean all keys in the array (recursive)
*/
function clean_var($data)
{
if(is_array($data))
{
//---
// Array
//---
// move through each element
while(list($k, $v) = each($data))
{
// recurse
$data[$k] = $this->clean_var($v);
}
}
else
{
//---
// Normal variable
//---
// get rid of slashes
if(get_magic_quotes_gpc())
$data = stripslashes($data);
// clean
$data = htmlspecialchars(urldecode($data), ENT_QUOTES);
$data = str_replace('(', '(', $data);
$data = str_replace(')', ')', $data);
}
// return
return $data;
}