PHP Filters are used to validating and sanitizing external input data. Validating data (Validate that external data is in the proper format or not) Sanitizing data (Remove illegal characters from external data).

PHP has many functions for checking, validating and cleaning external inputs.

PHP filter_list() functions is used to fetch the list of PHP filter extensions.

Below is the example of PHP filter_list() and filter_id() functions

<!DOCTYPE html>
<h1>PHP Filter</h1>
<th>Filter Name</th>
<th>Filter ID</th>
foreach (filter_list() as $filter) {
echo '<tr><td>' . $filter . '</td><td>' . filter_id($filter) . '</td></tr>';

The above code produces the following results


Filter Name         Filter ID

int                         257

boolean                 258

float                         259

validate_regexp 272

validate_url         273

validate_email         274

validate_ip         275

string                 513

stripped                 513

encoded                 514

special_chars         515

full_special_chars 522

unsafe_raw         516

email                 517

url                         518

number_int         519

number_float         520

magic_quotes         521

callback                 1024

Mostly application receive external data and external data can be in right format or wrong format, so we should validate, verify and cleaning the external data.

These are the PHP filter_var() function with different parameters

filter_var($ip, FILTER_VALIDATE_IP);

filter_var($string, FILTER_SANITIZE_STRING);

filter_var($int, FILTER_VALIDATE_INT);

filter_var($url, FILTER_SANITIZE_URL);

filter_var($email, FILTER_VALIDATE_EMAIL);

filter_var($email, FILTER_SANITIZE_EMAIL);

Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic