PHP Programing language

adplus-dvertising
Previous Home Next

Filters in Php

PHP filters are used to validating data means determine if the data is in proper form and sanitizing data means remove any illegal character from the data external input.

The PHP filter extension has many of the functions needed for checking user input, and is designed to make data validation easier and quicker.

Use of Filters

There are many web applications receive external input that is :

  • User input from a form
  • Cookies
  • Web services data
  • Server variables
  • Database query results

Example:

<html>
<head>
<style>
table, th, td 
{
border: 1px solid black;
border-collapse: collapse;
}
th, td 
{
padding: 8px;
}
</style>
</head>
<body>
<table>
<tr>
<td>Filter Name</td>
<td>Filter ID</td>
</tr>

<?php
foreach (filter_list() as $id =>$filter) 
{
echo '<tr><td>' . $filter . '</td><td>' . filter_id($filter) . '</td></tr>';
}
?>

</table>
</body>
</html>

Output:

Some Filter Functions are:
Function Name Description
filter_has_var() Checks if a variable of a specified input type exist
filter_id() Returns the filter ID of a specified filter name
filter_input() Gets an external variable (e.g. from form input) and optionally filters it.
filter_input_array() Gets external variables (e.g. from form input) and optionally filters them
filter_list() Returns a list of all supported filters
filter_var_array() Gets multiple variables and filter them
filter_var() Filters a variable with a specified filter
Previous Home Next