CKTIS / PHP
filter_input()
Lê um campo de entrada original do SAPI e aplica o filtro escolhido.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
filter_input(int $type, string $var_name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixedLê um campo de entrada original do SAPI e aplica o filtro escolhido. Alterações posteriores a $_GET não alteram esse campo. Um campo ausente dá normalmente null e uma validação falhada false. FILTER_NULL_ON_FAILURE troca os dois resultados.
Assinatura
filter_input(int $type, string $var_name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed
Saída do exemplo
[null,false,8]
Exemplos
<?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]