public static function sanitize($input, $skip = [], $textOnly = false, $removeFunctions = true)
    {
        if (!is_array($input)) {
            if (true === $removeFunctions) {
                $input = preg_replace('/[a-zA-Z][a-zA-Z0-9_]+(\()+([a-zA-Z0-9_\-$,\s\"]?)+(\))(\;?)/', '', $input);
            }

            $invalidValues = ['exec', '\\', '&amp;', '&#', '0x', '<script>', '</script>', '">', "'>"];
            $allowableTags = '<p><br><img><label><input><textarea><div><span><a><strong><i><u>';
            $input = str_replace($invalidValues, '', $input);
            $input = preg_replace('/%[a-zA-Z0-9]{2}/', '', $input);
            $input = strip_tags(trim($input), $allowableTags);

            if ($textOnly) {
                $input = str_replace(['<', '>', "'", '"'], '', $input);
            }

            return $input;
        } else {

            $array = [];

            foreach ($input as $key => $item) {

                if (in_array($key, $skip)) {
                    $array[$key] = $item;
                } else {
                    if (!is_array($item)) {
                        $array[$key] = self::sanitize($item, $skip, $textOnly, $removeFunctions);
                    } else {
                        $array = array_merge($array, [$key => self::sanitize($item, $skip, $textOnly, $removeFunctions)]);
                    }
                }
            }

            return $array;
        }
    }
public static function sanitize($input, $skip = [], $textOnly = false, $removeFunctions = true)
    {
        if (!is_array($input)) {
            if (true === $removeFunctions) {
                $input = preg_replace('/[a-zA-Z][a-zA-Z0-9_]+(\()+([a-zA-Z0-9_\-$,\s\"]?)+(\))(\;?)/', '', $input);
            }

            $invalidValues = ['exec', '\\', '&amp;', '&#', '0x', '<script>', '</script>', '">', "'>"];
            $allowableTags = '<p><br><img><label><input><textarea><div><span><a><strong><i><u>';
            $input = str_replace($invalidValues, '', $input);
            $input = preg_replace('/%[a-zA-Z0-9]{2}/', '', $input);
            $input = strip_tags(trim($input), $allowableTags);

            if ($textOnly) {
                $input = str_replace(['<', '>', "'", '"'], '', $input);
            }

            return $input;
        } else {

            $array = [];

            foreach ($input as $key => $item) {

                if (in_array($key, $skip)) {
                    $array[$key] = $item;
                } else {
                    if (!is_array($item)) {
                        $array[$key] = self::sanitize($item, $skip, $textOnly, $removeFunctions);
                    } else {
                        $array = array_merge($array, [$key => self::sanitize($item, $skip, $textOnly, $removeFunctions)]);
                    }
                }
            }

            return $array;
        }
    }
public static function sanitize ( $ input , $ skip = [ ] , $ textOnly = false , $ removeFunctions = true ) { if ( ! is_array ( $ input ) ) { if ( true === $ removeFunctions ) { $ input = preg_replace ( '/[a-zA-Z][a-zA-Z0-9_]+(\()+([a-zA-Z0-9_\-$,\s\"]?)+(\))(\;?)/' , '' , $ input ) ; } $ invalidValues = [ 'exec' , '\\' , '&amp;' , '&#' , '0x' , '<script>' , '</script>' , '">' , "'>" ] ; $ allowableTags = '<p><br><img><label><input><textarea><div><span><a><strong><i><u>' ; $ input = str_replace ( $ invalidValues , '' , $ input ) ; $ input = preg_replace ( '/%[a-zA-Z0-9]{2}/' , '' , $ input ) ; $ input = strip_tags ( trim ( $ input ) , $ allowableTags ) ; if ( $ textOnly ) { $ input = str_replace ( [ '<' , '>' , "'" , '"' ] , '' , $ input ) ; } return $ input ; } else { $ array = [ ] ; foreach ( $ input as $ key => $ item ) { if ( in_array ( $ key , $ skip ) ) { $ array [ $ key ] = $ item ; } else { if ( ! is_array ( $ item ) ) { $ array [ $ key ] = self :: sanitize ( $ item , $ skip , $ textOnly , $ removeFunctions ) ; } else { $ array = array_merge ( $ array , [ $ key => self :: sanitize ( $ item , $ skip , $ textOnly , $ removeFunctions ) ] ) ; } } } return $ array ; } }
Sanitizes or recursively sanitizes a value

@param $input
@param array $skip
@param bool $textOnly
@param bool $removeFunctions

@return array|mixed|string
Sanitizes or recursively sanitizes a value