Created
June 2, 2016 15:35
-
-
Save jrobinsonc/65d7a78519fc30ee6057847aff2b448d to your computer and use it in GitHub Desktop.
PHP helper: clean_value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function clean_value($value, $format = '') | |
{ | |
if (is_array($value)) | |
{ | |
foreach ($value as $k => $v) | |
{ | |
$value[$k] = clean_value($v, $format); | |
} | |
} | |
else | |
{ | |
// Default filters | |
if ($format === '') $format = 'strip_tags|trim'; | |
$format_filters = explode('|', $format); | |
foreach ($format_filters as $filter) | |
{ | |
switch ($filter) | |
{ | |
case 'string': | |
$value = filter_var($value, FILTER_SANITIZE_STRING); | |
break; | |
default: | |
if (function_exists($filter)) | |
$value = call_user_func($filter, $value); | |
break; | |
} | |
} | |
} | |
return $value; | |
} | |
function _GET($name, $format = '') | |
{ | |
return isset($_GET[$name])? clean_value($_GET[$name], $format) : null; | |
} | |
function _POST($name, $format = '') | |
{ | |
return isset($_POST[$name])? clean_value($_POST[$name], $format) : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment