Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / PHP

filter_input()

Lee un campo original del SAPI y aplica el filtro indicado.

Versión: PHP 8.4; repository runtime, production runtime not attested

Sintaxis

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

Lee un campo original del SAPI y aplica el filtro indicado. Modificar $_GET después no altera ese campo. Por defecto un campo ausente da null y un fallo de validación false. FILTER_NULL_ON_FAILURE intercambia ambos resultados.

Firma

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

Salida del ejemplo

[null,false,8]

Ejemplos

<?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)]);

Resultado

[null,false,8]

Fuentes