本文整理汇总了PHP中filter_var_array函数的典型用法代码示例。如果您正苦于以下问题:PHP filter_var_array函数的具体用法?PHP filter_var_array怎么用?PHP filter_var_array使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了filter_var_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find
public function find()
{
$options = ['page' => FILTER_SANITIZE_NUMBER_INT, 'limit' => FILTER_SANITIZE_NUMBER_INT, 'type' => FILTER_SANITIZE_NUMBER_INT];
$values = filter_input_array(INPUT_GET, $options);
if (is_array($values)) {
$options['page'] = FILTER_VALIDATE_INT;
$options['limit'] = FILTER_VALIDATE_INT;
$options['type'] = FILTER_VALIDATE_INT;
$values = filter_var_array($values, $options);
}
if (empty($values) || $values['type'] === false) {
$this->render404();
return;
}
if ($values['page'] === false) {
$values['page'] = 1;
}
if ($values['limit'] === false) {
$values['limit'] = 10;
}
$news = $this->models->newsModel->paginateByType($values['type'], $values['page'], $values['limit']);
$count = ceil($this->models->newsModel->count($values['type']) / (double) $values['limit']);
if (count($news)) {
$this->render('find', ['news' => $news, 'count' => $count, 'page' => $values['page']]);
} else {
$this->render404();
}
}
示例2: sanitize
/**
* @param array $data исходные данные.
* @param array $rules правила валидации.
* @param array $errors ошибки, возникшие в ходе проверок.
* @return array возвращает очищенные и отвалидированные данные согласано указанным правилам.
* @link http://php.net/manual/ru/function.filter-var-array.php
*/
function sanitize(array $data, array $rules, &$errors = null)
{
$errors = is_array($errors) ? $errors : [];
foreach ($rules as $key => $rule) {
$rule['flags'] = isset($rule['flags']) ? $rule['flags'] | FILTER_NULL_ON_FAILURE : FILTER_NULL_ON_FAILURE;
$rule['required'] = isset($rule['required']) ? (bool) $rule['required'] : false;
$rule['message'] = isset($rule['message']) ? $rule['message'] : '';
$rules[$key] = $rule;
}
$data = array_map('trim', $data);
$filteredData = filter_var_array($data, $rules);
foreach ($filteredData as $attribute => $value) {
$rule = $rules[$attribute];
if (is_null($value)) {
if ($data[$attribute] || $data[$attribute] === '' && $rule['required']) {
sanitizeAddError($attribute, $rule['message'] ?: 'Не корректное значение в поле "{attribute}".', $errors);
}
}
if (is_string($value)) {
$value = trim($value);
$filteredData[$attribute] = $value;
if (!$value && $rule['required']) {
sanitizeAddError($attribute, $rule['message'] ?: 'Не заполнено обязательное поле "{attribute}".', $errors);
}
}
}
return $filteredData;
}
示例3: decode
public function decode($input)
{
$arr = explode(' ', $input);
$decodedInput = $output = array();
for ($i = 0; $i < count($arr); $i++) {
$nextElement = $i+1;
$key = substr($arr[$i], 1);
if ($this->parameterExistsInSchema($key)) {
if ($this->parameterHasValue($arr, $nextElement)) {
if ($this->parameterIsArray($key)) {
$value = explode(',', $arr[$nextElement]);
} else {
$value = $arr[$nextElement];
}
$i++;
} else {
$value = true;
}
} else {
throw new Exception("Parameter {$key} not defined");
}
$decodedInput[$key] = $value;
}
return filter_var_array($decodedInput, $this->schema);
}
示例4: sanitize
public static function sanitize(array $data, array $rules, $errors)
{
$errors = is_array($errors) ? $errors : [];
foreach ($rules as $key => $rule) {
$rule['flags'] = isset($rule['flags']) ? $rule['flags'] | FILTER_NULL_ON_FAILURE : FILTER_NULL_ON_FAILURE;
$rule['required'] = isset($rule['required']) ? (bool) $rule['required'] : false;
$rule['message'] = isset($rule['message']) ? $rule['message'] : '';
$rules[$key] = $rule;
}
$data = filter_var_array($data, $rules);
foreach ($data as $attribute => $value) {
$rule = $rules[$attribute];
if (is_null($value)) {
self::addError($attribute, $rule['message'] ?: 'Не корректное значение в поле "{attribute}".', $errors);
}
if (is_string($value)) {
if (!$value && $rule['required']) {
self::addError($attribute, $rule['message'] ?: 'Не заполнено обязательное поле "{attribute}".', $errors);
}
}
}
if (array_key_exists('password', $data) and array_key_exists('password_repeat', $data)) {
if ($data['password'] != $data['password_repeat']) {
self::$errors['password_repeat'] = 'Пароли не совпадают "password_repeat".';
}
}
return $data;
}
示例5: __construct
public function __construct()
{
parent::sessionStart();
$filterArgs = array('tm_key' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'downloadToken' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'source' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'target' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH));
$__postInput = filter_var_array($_REQUEST, $filterArgs);
//NOTE: This is for debug purpose only,
//NOTE: Global $_POST Overriding from CLI Test scripts
//$__postInput = filter_var_array( $_POST, $filterArgs );
$this->tm_key = $__postInput['tm_key'];
$this->source = $__postInput['source'];
$this->target = $__postInput['target'];
$this->downloadToken = $__postInput['downloadToken'];
parent::disableSessions();
$userIsLogged = isset($_SESSION['cid']) && !empty($_SESSION['cid']);
if (!$userIsLogged) {
$output = "<pre>\n";
$output .= " - REQUEST URI: " . print_r(@$_SERVER['REQUEST_URI'], true) . "\n";
$output .= " - REQUEST Message: " . print_r($_REQUEST, true) . "\n";
$output .= "\n\t";
$output .= "Aborting...\n";
$output .= "</pre>";
Log::$fileName = 'php_errors.txt';
Log::doLog($output);
Utils::sendErrMailReport($output, "Download TMX Error: user Not Logged");
$this->unlockToken();
exit;
}
$this->uid = isset($_SESSION['uid']) && !empty($_SESSION['uid']) ? $_SESSION['uid'] : null;
$this->userMail = isset($_SESSION['cid']) && !empty($_SESSION['cid']) ? $_SESSION['cid'] : null;
$this->tmxHandler = new TMSService();
$this->tmxHandler->setTmKey($this->tm_key);
}
示例6: route
/**
* @return string|false
* @throws \RuntimeException
*/
protected function route()
{
$path = $this->getPathInfo();
if (empty($path)) {
$controllerName = 'index';
$actionName = 'index';
$args = array();
} else {
$segments = explode('/', $path);
$controllerName = $segments[0];
$actionName = isset($segments[1]) ? $segments[1] : 'index';
$args = filter_var_array(array_slice($segments, 2), FILTER_SANITIZE_STRING);
}
$class = '\\Readr\\Controller\\' . ucfirst($controllerName) . 'Controller';
if (!class_exists($class)) {
throw new \Exception("Page not found", 404);
}
$controller = new $class($this->getServiceManager());
$method = $actionName . 'Action';
if (!method_exists($controller, $method)) {
throw new \Exception("Page not found", 404);
}
$response = call_user_func_array(array($controller, $method), $args);
if (is_string($response)) {
return $response;
} elseif (is_array($response) || is_null($response)) {
$template = 'readr/views/' . strtolower($controllerName) . '/' . strtolower($actionName) . '.phtml';
$view = new View($template, $response);
$layout = new View('readr/views/layout.phtml', array('title' => 'Readr', 'content' => $view->render()));
return $layout->render();
}
return false;
}
示例7: sanitize
function sanitize(array $data, array $rules, array &$errors = null)
{
$errors = is_array($errors) ? $errors : [];
//если приходит не массив, то превратить в массив
//1. этап - подготовка правил валидации / фильтрации
foreach ($rules as $attribute => $rule) {
$rule['flags'] = isset($rule['flags']) ? $rule['flags'] | FILTER_NULL_ON_FAILURE : FILTER_NULL_ON_FAILURE;
$rule['required'] = isset($rule['required']) ? (bool) $rule['required'] : false;
$rule['message'] = isset($rule['message']) ? $rule['message'] : '';
$rules[$attribute] = $rule;
}
//var_dump($rules);
//2. этап - непосредственно валидации / фильтрации
$data = array_map('trim', $data);
$filterData = filter_var_array($data, $rules);
foreach ($filterData as $attribute => $value) {
$rule = $rules[$attribute];
if (is_null($value)) {
if ($data[$attribute] || $data[$attribute] === '' && $rule['required']) {
sanitizeAddError($attribute, $rule['message'] ?: 'Некорректное значение в поле {attribute}', $errors);
}
}
if (is_string($value)) {
$value = trim($value);
//обрезаем пробелы,если есть лишние
$filterData[$attribute] = $value;
if (!$value && $rule['required']) {
sanitizeAddError($attribute, $rule['message'] ?: 'Не заполнено обязательное поле {attribute}', $errors);
}
}
}
return $filterData;
}
示例8: filter_array
public function filter_array($data = NULL, $filter = NULL, $options = NULL)
{
if (isset($filter)) {
$this->filter = $filter;
}
return filter_var_array($data, $this->filter);
}
示例9: validate_params
function validate_params($method, $params, $validators, $sanitizers)
{
if ($method == 'GET') {
$grab = $_GET;
} else {
if ($method == 'POST') {
$grab = $_POST;
}
}
$result = array();
$filters = array();
for ($i = 0; $i < count($validators); $i++) {
if (isset($grab[$params[$i]])) {
$filters[$params[$i]] = $validators[$i];
} else {
return false;
}
}
$result = filter_var_array($grab, $filters);
$filters = array();
for ($i = 0; $i < count($sanitizers); $i++) {
if ($result[$params[$i]] !== false) {
$filters[$params[$i]] = $sanitizers[$i];
} else {
return false;
}
}
return filter_var_array($result, $filters);
}
示例10: addRepublica
/**
* @param (float|int|string)[] $republica
* @param int $who_posted
*/
public static function addRepublica(array $republica, $whoPosted, Database &$database)
{
$filterFloat = array('filter' => FILTER_SANITIZE_NUMBER_FLOAT, 'flags' => FILTER_FLAG_ALLOW_FRACTION);
$options = array('name' => FILTER_SANITIZE_STRING, 'latitude' => $filterFloat, 'longitude' => $filterFloat, 'phone' => FILTER_SANITIZE_STRING, 'email' => FILTER_SANITIZE_EMAIL, 'address' => FILTER_SANITIZE_STRING, 'more' => FILTER_SANITIZE_STRING);
$republica = filter_var_array($republica, $options);
$whoPosted = filter_var($whoPosted, FILTER_SANITIZE_NUMBER_INT);
$valid = (bool) filter_var($republica['email'], FILTER_VALIDATE_EMAIL);
$valid &= (bool) filter_var($whoPosted, FILTER_VALIDATE_INT);
$success = false;
if ($valid) {
$query = $database->prepare('
INSERT INTO republicas (
name, latitude, longitude, phone, email,
address, who_posted, more
) VALUES (
:name, :latitude, :longitude, :phone, :email,
:address, :who_posted, :more
)
');
do {
$query->bindParam(':' . key($republica), current($republica));
} while (next($republica) !== false);
$query->bindParam(':who_posted', $whoPosted, Database::PARAM_INT);
$success = $query->execute();
}
return $success;
}
示例11: process
static function process($filters, $source = INPUT_POST, $required_by_default = false, $strict = true)
{
# parse filters
list($filters, $required, $defaults) = self::parse_filters($filters, $required_by_default);
# apply
$d = is_array($source) ? filter_var_array($source, $filters) : filter_input_array($source, $filters);
if ($d === null) {
$d = array_fill_keys(array_keys($filters), null);
}
# check required and set undefined to null (rather than false)
foreach ($filters as $field => $filter) {
$isa = is_array($filter);
if ($d[$field] === null || $d[$field] === false && ($isa ? $filter['filter'] : $filter) !== FILTER_VALIDATE_BOOLEAN) {
if ($strict && isset($required[$field])) {
throw new UnexpectedValueException($field . ' is required');
} elseif (isset($defaults[$field])) {
if ($filter !== FILTER_DEFAULT) {
if ($isa) {
$d[$field] = filter_var($defaults[$field], $filter['filter'], isset($filter['options']) ? $filter['options'] : null);
} else {
$d[$field] = filter_var($defaults[$field], $filter);
}
} else {
$d[$field] = $defaults[$field];
}
} else {
$d[$field] = null;
}
}
}
return $d;
}
示例12: sanitizeInputArray
/**
* @param $data
* @return mixed
*/
public function sanitizeInputArray($data)
{
$filter = FILTER_SANITIZE_STRING;
$flags = [FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_LOW];
$args = $this->recursiveArgs($data, $filter, $flags);
return filter_var_array($data, $args);
}
示例13: find
public function find()
{
$options = ['page' => FILTER_SANITIZE_NUMBER_INT, 'limit' => FILTER_SANITIZE_NUMBER_INT];
$values = filter_input_array(INPUT_GET, $options);
if (is_array($values)) {
$options['page'] = FILTER_VALIDATE_INT;
$options['limit'] = FILTER_VALIDATE_INT;
$values = filter_var_array($values, $options);
}
if (empty($values)) {
$values = ['page' => false, 'limit' => false];
}
if ($values['page'] === false) {
$values['page'] = 1;
}
if ($values['limit'] === false) {
$values['limit'] = 10;
}
$messages = $this->models->messageModel->paginate($values['page'], $values['limit'], ['date DESC']);
$count = $this->models->messageModel->count();
if (count($messages)) {
$this->render('find', ['messages' => $messages, 'count' => $count, 'page' => $values['page']]);
} else {
$this->render404();
}
}
示例14: accountNightmode
function accountNightmode()
{
require "functions/common.php";
require "functions/import_info.php";
if (isset($_GET['accountNightmode'])) {
if (empty($_POST['nightmode_state'])) {
die("You missed a field");
header("Location: " . $_SERVER['SCRIPT_NAME']);
}
$_POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
$email = $_SESSION['user']['email'];
$first_name = $row_info['first_name'];
$last_name = $row_info['last_name'];
$birthday = $row_info['birthday'];
$nightmode = $_POST['nightmode_state'];
$user_id = $row_info['id'];
$query = "\n\t\t\tREPLACE INTO info (\n\t\t\t\tid,\n\t\t\t\temail,\n\t\t\t\tfirst_name,\n\t\t\t\tlast_name,\n\t\t\t\tbirthday,\n\t\t\t\tnightmode\n\t\t\t) VALUES (\n\t\t\t\t'{$user_id}',\n\t\t\t\t'{$email}',\n\t\t\t\t'{$first_name}',\n\t\t\t\t'{$last_name}',\n\t\t\t\t'{$birthday}',\n\t\t\t\t'{$nightmode}'\n\t\t\t);";
try {
$stmt = $db->prepare($query);
$stmt->execute();
header("Location: " . $_SERVER['SCRIPT_NAME']);
} catch (PDOException $ex) {
die("Failed to run query: " . $ex->getMessage());
header("Location: " . $_SERVER['SCRIPT_NAME']);
}
}
}
示例15: startInit
/** startInit() initiates the environment
* @return void
*/
public static function startInit()
{
@set_time_limit(0);
@error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
@ini_set('session.save_handler', 'mm');
@ini_set('session.cookie_httponly', true);
@ob_start('sanitize_output');
@session_start();
@session_cache_limiter('no-cache');
@session_set_cookie_params(0, null, null, true, true);
@set_magic_quotes_runtime(0);
self::verCheck();
self::extCheck();
foreach ($_REQUEST as $key => $val) {
$_REQUEST[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING);
}
foreach ($_GET as $key => $val) {
$_GET[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING);
}
foreach ($_POST as $key => $val) {
$_POST[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING);
}
foreach (array('node', 'sub', 'printertype', 'id', 'sub', 'crit', 'sort', 'confirm', 'tab') as $x) {
global ${$x};
${$x} = isset($_REQUEST[$x]) ? filter_var($_REQUEST[$x], FILTER_SANITIZE_STRING) : '';
}
unset($x);
new System();
new Config();
}