- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
function string_cleaner($data, array $opts) //1: Массив или строка, 2: Только массив
{
if (empty($opts))
{
$opts['null_byte'] = TRUE;
}
$null_byte = ($opts['null_byte'] == 'off')
? FALSE
: TRUE;
$opts_allowed = ['trim', 'htmlspecialchars', 'strip_tags', 'addslashes', 'htmlentities'];
$opts = array_intersect_key($opts, array_flip($opts_allowed));
if(is_array($data))
{
foreach($data as $key => &$value)
{
if(is_array($value))
{
string_cleaner($value, $opts);
}
if ($null_byte)
{
$value = str_replace(chr(0), '', $value);
}
if(is_array($opts))
{
foreach($opts as $clear_func => $clear_func_params)
{
$value = (!$clear_func_params) ? $clear_func($value) : $clear_func($value, $clear_func_params);
}
}
}
}
else
{
if ($null_byte)
{
$data = str_replace(chr(0), '', $data);
}
if(is_array($opts))
{
foreach($opts as $clear_func => $clear_func_params)
{
$data = $value = (!$clear_func_params) ? $clear_func($data) : $clear_func($data, $clear_func_params);
}
}
}
return $data;
}
{...}
$server['get'] = string_cleaner($_GET, ['trim'=>' ', 'htmlentities'=>'', 'strip_tags'=>'', 'addslashes'=>'']);