ExamVeda
Login
Home
21
What will be the output of the following PHP code?
<?php
$number = array(0,1,two,three,four,5);
$num = preg_grep("/[0-5]/", $number);
print_r($num);
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The preg_grep function is used to search an array for specific patterns and then return a new array based on that filtering.
22
What will be the output if we replace the line $num = preg_grep(“/[0-5]/”, $number); with $num = preg_grep(“/[0-5]/”, $number, PREG_GREP_INVERT);?
Discuss
Answer & Solution
Answer: Option B
Solution:
When we include PREG_GREP_INVERT, this will invert our data, so instead of outputting numbers it will output our non-numeric values.
23
Which one of the following functions is used to search a string?
Discuss
Answer & Solution
Answer: Option A
Solution:
The function returns 1 if search was successful else returns 0.
24
What will be the output of the following PHP code?
<?php
$name = "What is your name?"
if (preg_match("/name/"),$name)
  echo "My name is Will Pitt ";
else
  echo "My name is not Will Pitt ";
if (preg_match("/are/"))
  echo "I am great"
else
  echo "I am not great";    
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The code uses preg_match to check for a keyword and replies based on whether it is true (1) or false (0).
25
Which one of the following preg PHP function is used to do a find and replace on a string or an array?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
26
What will be the output of the following PHP code?
<?php
$str = "Hello! My name is Cameron Fox. Coffee?"
$find = array('/is/','/coffee/');
$replace = array('/was/','/tea/');
echo preg_replace ($find, $replace, $str);
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
Coffee was not replaced because the preg_replace function is case sensitive. Therefore it treats coffee and Coffee differently.
27
Which one of the following preg PHP functions is used to take a string, and put it in an array?
Discuss
Answer & Solution
Answer: Option B
Solution:
The string is broken up into different values in the array based upon your input.
28
What will be the output of the following PHP code?
<?php
$line = "You like dogs. I hate dogs. We should marry."
$sen = preg_split('/./', $line);
print_r($sen);
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
We use a ‘.’ period to split the data, therefor giving each sentence it’s own array entry.
29
Which one of the following is not a preg PHP function?
Discuss
Answer & Solution
Answer: Option C
Solution:
The function preg_matchall does not exist. preg_match_all is a preg function.
30
Parameter flags was added in which version of PHP?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board