Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

filter_input()

Example

Retrieves an external variable (e.g., from form input) and optionally applies a filter to it.

<?php
if (!filter_input(INPUT_GET, “email”, FILTER_VALIDATE_EMAIL)) {
    echo(“Email is not valid”);
else {
    echo(“Email is valid”);
}
?>

Definition and Usage

The filter_input() function retrieves an external variable (e.g., from form input) and optionally applies a filter to it.

 

It is used to validate variables from insecure sources, such as user input.

Syntax

filter_input(type, variable, filter, options)

Parameter Values

 

Parameter

Description

type

Required. Specifies the input type to check for, which can be one of the following:

·         INPUT_GET

·         INPUT_POST

·         INPUT_COOKIE

·         INPUT_SERVER

·         INPUT_ENV

variable

Required. Specifies the name of the variable to retrieve.

filter

Optional. Specifies the ID or name of the filter to apply. The default is `FILTER_DEFAULT

options

Optional. Specifies one or more flags or options to apply. Refer to each filter’s documentation for available options and flags.

Technical Details

Return Value:

The variable’s value on success, FALSE on failure, or NULL if the variable is not set.

PHP Version:

5.2+