CKTIS / PHP
filter_input()
Odczytuje oryginalne pole wejściowe SAPI i stosuje wskazany filtr.
Wersja: PHP 8.4; repository runtime, production runtime not attested
Składnia
filter_input(int $type, string $var_name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixedOdczytuje oryginalne pole wejściowe SAPI i stosuje wskazany filtr. Późniejsza zmiana $_GET nie zmieni tej wartości. Domyślnie brak pola daje null, a błąd walidacji false. FILTER_NULL_ON_FAILURE zamienia te dwa znaczniki miejscami.
Sygnatura
filter_input(int $type, string $var_name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed
Wynik przykładu
[null,false,8]
Przykłady
<?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)]);
Wynik
[null,false,8]