Php Regular Expressions(Engineering > Computer Science And Engineering > Php ) Questions and Answers

Question 1. PHP has long supported two regular expression implementations known as _______ and _______.1. Perl2. PEAR3. Pearl4. POSIX
  1.    1 and 2
  2.    2 and 4
  3.    1 and 4
  4.    2 and 3
Explanation:-
Answer: Option C. -> 1 and 4

Question 2. Which one of the following regular expression matches any string containing zero or one p?
  1.    P?
  2.    p+
  3.    p#
  4.    p*
Explanation:-
Answer: Option A. -> P?

Question 3. How many functions does PHP offer for searching strings using POSIX style regular expression?
  1.    8
  2.    10
  3.    9
  4.    7
Explanation:-
Answer: Option D. -> 7

Question 4. [:alpha:] can also be specified as.
  1.    [A-z]
  2.    [a-z]
  3.    [A-Za-z0-9]
  4.    [A-za-z]
Explanation:-
Answer: Option D. -> [A-za-z]

Question 5. What will be the output of the following PHP code?$username = "jasoN";if (ereg("([^a-z])",$username))echo "Username must be all lowercase!";elseecho "Username is all lowercase!";
  1.    Error
  2.    Username is all lowercase!
  3.    No Output is returned
  4.    Username must be all lowercase!
Explanation:-
Answer: Option D. -> Username must be all lowercase!

Question 6. POSIX stands for
  1.    Portative Operating System Interface for Unix
  2.    Portable Operating System Interface for Linux
  3.    Portative Operating System Interface for Linux
  4.    Portable Operating System Interface for Unix
Explanation:-
Answer: Option D. -> Portable Operating System Interface for Unix

Question 7. Which among the following is/are not a metacharacter?1. /a2. /A3. /b4. /B
  1.    2, 3 and 4
  2.    2 and 4
  3.    1 and 3
  4.    Only 1
Explanation:-
Answer: Option D. -> Only 1

Question 8. Which of the following would be a potential match for the Perl-based regular expression /fo{2,4}/ ?1. fol2. fool3. fooool4. fooooool
  1.    Only 1
  2.    1 and 4
  3.    1, 3 and 4
  4.    2 and 3
Explanation:-
Answer: Option D. -> 2 and 3

Question 9. What will be the output of the following PHP code?$text = "this istsome text thatnwe might like to parse.";print_r(split("[nt]",$text));
  1.    this is some text that we might like to parse.
  2.    Array ( [0] => some text that [1] => we might like to parse. )
  3.    Array ( [0] => this is [1] => some text that [2] => we might like to parse. )
  4.    [0] => this is [1] => some text that [2] => we might like to parse.
Explanation:-
Answer: Option D. -> [0] => this is [1] => some text that [2] => we might like to parse.

Question 10. POSIX implementation was deprecated in which version of PHP?
  1.    PHP 5.2
  2.    PHP 5
  3.    PHP 5.3
  4.    PHP 4
Explanation:-
Answer: Option C. -> PHP 5.3