Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

filter_input()

Read one original SAPI input field and apply the requested filter.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

filter_input(int $type, string $var_name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed

Read one original SAPI input field and apply the requested filter. Editing $_GET later leaves that original field untouched. Normally a missing field yields null and failed validation yields false. FILTER_NULL_ON_FAILURE swaps these two failure markers.

Signature

filter_input(int $type, string $var_name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed

Example output

[null,false,8]

Examples

<?php
$_GET["page"]="8";
echo json_encode([filter_input(INPUT_GET,"page",FILTER_VALIDATE_INT),filter_input(INPUT_GET,"page",FILTER_VALIDATE_INT,FILTER_NULL_ON_FAILURE),filter_var($_GET["page"],FILTER_VALIDATE_INT)]);

Result

[null,false,8]

Sources