ExamVeda
Login
Home
1
Which of the following is/are an external data?
1. Cookies
2. Input data from a form
3. Server Variables
4. Web services data
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
2
How many types of filtering are present in PHP?
Discuss
Answer & Solution
Answer: Option B
Solution:
There are two main types of filtering: validation and sanitization.
3
Which one of the following filter is used to filter several variables with the same or different filters?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
4
What will be the output of the following PHP code?
<?php
$num = "123";
if (!filter_var($num, FILTER_VALIDATE_INT))
    echo("Integer is not valid");
else
    echo("Integer is valid");
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
filter_var() – Filters a single variable with a specified filter.
5
Which one of the following does not describe a validating filter?
Discuss
Answer & Solution
Answer: Option A
Solution:
Option a) describes Sanitizing filters.
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");
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
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”.
7
Which one of the following filter checks if variable of specified type exists?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
8
What will be the output of the following PHP code?
<?php
$value = 'car';
$result = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
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.
9
What will be the output of the following PHP code?
<?php
function convertSpace($string)
{
  return str_replace("_", " ", $string);
}
$string = "Peter_is_a_great_guy!";
echo filter_var($string, FILTER_CALLBACK, array("options"=>"convertSpace"));
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The code above converts all “_” to white spaces. Call the filter_var() function with the FILTER_CALLBACK filter and an array containing our function.