Php Filter(Php ) Questions and Answers

Question 1. Which one of the following filter is used to filter several variables with the same or different filters?
  1.    filter_var_array()
  2.    filter_var()
  3.    filter_input
  4.    filter_input_array
Explanation:-
Answer: Option A. -> filter_var_array()

Question 2. What will be the output of the following PHP code?
  1.    No output is returned
  2.    Integer is not valid
  3.    Integer is valid
  4.    Error
Explanation:-
Answer: Option C. -> Integer is valid
filter_var() – Filters a single variable with a specified filter.

Question 3. Which of the following is/are an external data?
1. Cookies
2. Input data from a form
3. Server Variables
4. Web services data
  1.    Only 2
  2.    2 and 3
  3.    None of the mentioned
  4.    All of the mentioned
Explanation:-
Answer: Option D. -> All of the mentioned

Question 4. How many types of filtering are present in PHP?
  1.    3
  2.    2
  3.    4
  4.    None
Explanation:-
Answer: Option B. -> 2
There are two main types of filtering: validation and sanitization.

Question 5. Which one of the following does not describe a validating filter?
  1.    Are used to allow or disallow specified characters in a string
  2.    Are used to validate user input
  3.    Strict format rules
  4.    Returns the expected type on success or FALSE on failure
Explanation:-
Answer: Option A. -> Are used to allow or disallow specified characters in a string
Option a) describes Sanitizing filters.

Question 6. What will be the output of the following PHP code?
<?php
$var=300;
$int_options = array("options"=>array ("min_range"=>0, "max_range"=>256));
if (!filter_var($var, FILTER_VALIDATE_INT, $int_options))
echo("Integer is not valid");
else
echo("Integer is valid");
?>
  1.    No output is returned
  2.    Integer is not valid
  3.    Integer is valid
  4.    Error
Explanation:-
Answer: Option B. -> Integer is not valid
Since the integer is “300” it is not in the specified range, and the output of the code above will be: “Integer is not valid”.

Question 7. Which one of the following filter checks if variable of specified type exists?
  1.    filter_has_var
  2.    filter_var
  3.    filter_id
  4.    filter_var_array
Explanation:-
Answer: Option A. -> filter_has_var

Question 8. What will be the output of the following PHP code?
  1.    FALSE
  2.    TRUE
  3.    NULL
  4.    ERROR
Explanation:-
Answer: Option C. -> NULL
There is an undocumented filter flag for FILTER_VALIDATE_BOOLEAN. The documentation implies that it will return NULL if the value doesn’t match the allowed true/false values. However this doesn’t happen unless you give it the FILTER_NULL_ON_FAILURE flag.

Question 9. What will be the output of the following PHP code?
  1.    Peter_is_a_great_guy!
  2.    Peterisagreatguy!
  3.    Peter is a great guy!
  4.    Error
Explanation:-
Answer: Option C. -> Peter is a great guy!
The code above converts all “_” to white spaces. Call the filter_var() function with the FILTER_CALLBACK filter and an array containing our function.