Which function is used to filter data from external sources like GET, POST, COOKIE?
Analysis & Theory
`filter_input()` fetches a specific external variable (like GET or POST) and optionally filters it.
What does the `FILTER_VALIDATE_FLOAT` filter do?
A
Sanitizes a float number
B
Validates if the variable is a valid float
C
Converts string to float
D
Rounds the float number
Analysis & Theory
`FILTER_VALIDATE_FLOAT` checks if the variable is a valid float value.
Which filter flag allows validating an integer within a range?
B
FILTER_VALIDATE_INT with options
Analysis & Theory
Use `FILTER_VALIDATE_INT` with an `options` array specifying `min_range` and `max_range`.
What does this code return?
```
filter_var(25, FILTER_VALIDATE_INT, ["options" => ["min_range" => 10, "max_range" => 20]]);
```
Analysis & Theory
25 is outside the specified range (10-20), so it returns `false`.
Which flag in URL validation requires the URL to contain a query string?
A
FILTER_FLAG_QUERY_REQUIRED
B
FILTER_FLAG_PATH_REQUIRED
C
FILTER_FLAG_SCHEME_REQUIRED
D
FILTER_FLAG_HOST_REQUIRED
Analysis & Theory
`FILTER_FLAG_QUERY_REQUIRED` requires that the URL contains a query string (?key=value).
What does `FILTER_FLAG_IPV6` do in IP validation?
A
Validates only IPv4 addresses
B
Validates both IPv4 and IPv6
C
Validates only IPv6 addresses
D
Ignores invalid IP addresses
Analysis & Theory
`FILTER_FLAG_IPV6` ensures that only valid IPv6 addresses are accepted.
How do you validate if a string is a valid boolean using filters?
B
FILTER_VALIDATE_BOOLEAN
Analysis & Theory
`FILTER_VALIDATE_BOOLEAN` returns true or false for boolean-like strings like '1', 'true', 'on'.
Which filter would you use to remove all characters except digits and + - ( ) from a phone number?
B
FILTER_SANITIZE_NUMBER_INT
C
FILTER_SANITIZE_NUMBER_FLOAT
Analysis & Theory
`FILTER_SANITIZE_NUMBER_INT` removes all characters except digits, plus (+), and minus (-) signs.
How can you apply different filters to multiple input variables from GET method at once?
A
filter_input_array(INPUT_GET, filters_array)
B
filter_var_array(INPUT_GET, filters_array)
C
validate_inputs(INPUT_GET, filters_array)
D
filter_all(INPUT_GET, filters_array)
Analysis & Theory
`filter_input_array(INPUT_GET, filters_array)` applies a set of filters to multiple GET variables.
What is the main difference between `filter_input()` and `filter_var()`?
A
`filter_input()` works with external data, `filter_var()` works with any variable
B
`filter_var()` requires HTTP request, `filter_input()` doesn't
D
`filter_var()` works only on $_POST
Analysis & Theory
`filter_input()` is for data from external sources like GET, POST, COOKIE, etc., whereas `filter_var()` applies filters to any local or external variable.