<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/refs.basic.vartype.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'book.filter.php',
    1 => 'Filter',
    2 => 'Data Filtering',
  ),
  'up' => 
  array (
    0 => 'refs.basic.vartype.php',
    1 => 'Variable and Type Related Extensions',
  ),
  'prev' => 
  array (
    0 => 'function.ctype-xdigit.php',
    1 => 'ctype_xdigit',
  ),
  'next' => 
  array (
    0 => 'filter.setup.php',
    1 => 'Installing/Configuring',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/filter/book.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/book.filter.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="book.filter" class="book">
 
 <h1 class="title">Data Filtering</h1>
 

 <div id="intro.filter" class="preface">
  <h1 class="title">Introduction</h1>
  <p class="simpara">
   This extension provides filters which can be used to validate or sanitize data.
   This is especially useful when the data source contains unknown (or foreign) data,
   like user supplied input.
   For example, this data may come from an <abbr title="Hyper Text Markup Language">HTML</abbr> form.
  </p>
  <p class="simpara">
   There are two main types of filtering:
   <em>validation</em> and <em>sanitization</em>.
  </p>
  <p class="simpara">
   A validation filter is used to check if the data meets certain criteria.
   These filters are identified by the
   <strong><code><a href="filter.constants.php#constant.filter-validate-bool">FILTER_VALIDATE_<span class="replaceable">*</span></a></code></strong>
   constants.
   For example, the <strong><code><a href="filter.constants.php#constant.filter-validate-email">FILTER_VALIDATE_EMAIL</a></code></strong> filter
   can be used to determine if the data is a valid email address.
   However, it will never alter the input data.
  </p>
  <p class="simpara">
   Sanitization on the other hand will &quot;clean up&quot; the data,
   therefore it may alter the input data by adding or removing characters.
   These filters are identified by the
   <strong><code><a href="filter.constants.php#constant.filter-sanitize-string">FILTER_SANITIZE_<span class="replaceable">*</span></a></code></strong>
   constants.
   For example, the <strong><code><a href="filter.constants.php#constant.filter-sanitize-email">FILTER_SANITIZE_EMAIL</a></code></strong> filter will
   remove characters that are inappropriate for an email address to contain.
   However, the sanitized data is not validated to check if it is a valid
   email address.
  </p>
  <p class="simpara">
   Most filters support optional <em>flags</em> that can tweak
   the behavior of the filter.
   These flags are identified by the
   <strong><code><a href="filter.constants.php#constant.filter-flag-none">FILTER_FLAG_<span class="replaceable">*</span></a></code></strong>
   constants.
   For example, using the <strong><code><a href="filter.constants.php#constant.filter-flag-path-required">FILTER_FLAG_PATH_REQUIRED</a></code></strong> with
   the <strong><code><a href="filter.constants.php#constant.filter-validate-url">FILTER_VALIDATE_URL</a></code></strong> validation filter
   requires that the <abbr title="Uniform Resource Locator">URL</abbr> has a path
   (e.g. <code class="literal">/foo</code> in <code class="literal">https://example.org/foo</code>).
  </p>
 </div>

 







 





 




 








<ul class="chunklist chunklist_book"><li><a href="filter.setup.php">Installing/Configuring</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="filter.installation.php">Installation</a></li><li><a href="filter.configuration.php">Runtime Configuration</a></li></ul></li><li><a href="filter.constants.php">Predefined Constants</a></li><li><a href="filter.examples.php">Examples</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="filter.examples.validation.php">Validation</a></li><li><a href="filter.examples.sanitization.php">Sanitization</a></li></ul></li><li><a href="ref.filter.php">Filter Functions</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="function.filter-has-var.php">filter_has_var</a> — Checks if a variable of the specified type exists</li><li><a href="function.filter-id.php">filter_id</a> — Returns the filter ID belonging to a named filter</li><li><a href="function.filter-input.php">filter_input</a> — Gets a specific external variable by name and optionally filters it</li><li><a href="function.filter-input-array.php">filter_input_array</a> — Gets external variables and optionally filters them</li><li><a href="function.filter-list.php">filter_list</a> — Returns a list of all supported filters</li><li><a href="function.filter-var.php">filter_var</a> — Filters a variable with a specified filter</li><li><a href="function.filter-var-array.php">filter_var_array</a> — Gets multiple variables and optionally filters them</li></ul></li></ul></div><?php manual_footer($setup); ?>