Change language

PHP Filter_input () function

Syntax:
filter_input ($type, $variable_name, $filter, $options) 
Parameters:this the function takes four parameters as above and described below:
  • $type:this is a required parameter used to validate the input type. Filter list:
    • INPUT_GET
    • INPUT_POST
    • INPUT_COOKIE
    • INPUT_SERVER
    • INPUT_ENV
  • $variable_name:Required. It is used to store the name of the variable to be checked.
  • $filter:This is an optional parameter. It contains the name or ID of the filter. If this parameter is not set, then FILTER_DEFAULT is used.
  • $options:is an optional parameter used to specify one or more flags / options to use. It checks for possible choices and flags in each filter. If the filter parameters are accepted, the flags can be specified in the "flags" field of the array.
Returned value:returns the value of the variable on success, or False on error. If the parameter is not set, return NULL. If the FILTER_NULL_ON_FAILURE flag is used, it returns FALSE if the variable is not set and NULL if the filter fails.Example 1:
// PHP program for checking mail using a filter if (isset ( $_ GET [ "email" ])) { if (! filter_input (INPUT_GET , "email" , FILTER_VALIDATE_EMAIL) === false) { echo ( " Valid Email " ); } else { echo ( "Invalid Email" ); } }  
?>
Output:
Valid Email 
Example 2:  
// Input type: INPUT_GET input name: search
// filter name: FILTER_SANITIZE_SPECIAL_CHARS $search_variable_data = filter_input (INPUT_GET , ’search’ , FILTER_SANITIZE_SPECIAL_CHARS );  
// Input type: INPUT_GET input name: search
// filter name: FILTER_SANITIZE_ENCODED $search_url_data = filter_input (INPUT_GET, ’search’ , FILTER_SANITIZE_ENCODED); echo " Search for $search_variable_data. " ; echo " Search again. " ;  
?>
Output:
Search for tic tac & amp; toc. Search again. 
Links: http://php.net /manual/en/function.filter-input.php

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically