GUMP::filter PHP Method

filter() public method

Filter the input data according to the specified filter set.
public filter ( array $input, array $filterset ) : mixed
$input array
$filterset array
return mixed
    public function filter(array $input, array $filterset)
    {
        foreach ($filterset as $field => $filters) {
            if (!array_key_exists($field, $input)) {
                continue;
            }
            $filters = explode('|', $filters);
            foreach ($filters as $filter) {
                $params = null;
                if (strstr($filter, ',') !== false) {
                    $filter = explode(',', $filter);
                    $params = array_slice($filter, 1, count($filter) - 1);
                    $filter = $filter[0];
                }
                if (is_callable(array($this, 'filter_' . $filter))) {
                    $method = 'filter_' . $filter;
                    $input[$field] = $this->{$method}($input[$field], $params);
                } elseif (function_exists($filter)) {
                    $input[$field] = $filter($input[$field]);
                } elseif (isset(self::$filter_methods[$filter])) {
                    $input[$field] = call_user_func(self::$filter_methods[$filter], $input[$field], $params);
                } else {
                    throw new Exception("Filter method '{$filter}' does not exist.");
                }
            }
        }
        return $input;
    }

Usage Example

Beispiel #1
0
#!/usr/bin/php -q
<?php 
require "../gump.class.php";
$validator = new GUMP();
// What are noise words? http://support.dtsearch.com/webhelp/dtsearch/noise_words.htm
$_POST = array('words' => "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English");
$filters = array('words' => 'noise_words');
print_r($validator->filter($_POST, $filters));
All Usage Examples Of GUMP::filter