Q. Which of the following regular expression matches any string containing 0 or 1 P?

  • (A) p*
  • (B) p#
  • (C) p+
  • (D) P?
πŸ’¬ Discuss
βœ… Correct Answer: (D) P?

Q. [:hello:] can also be specified as ___________

  • (A) [a-z]
  • (B) [A-z]
  • (C) [A-za-z]
  • (D) [A-Za-z0-9]
πŸ’¬ Discuss
βœ… Correct Answer: (C) [A-za-z]

Q. How many functions does PHP provide for searching strings using POSIX style regular expression?

  • (A) 5
  • (B) 6
  • (C) 7
  • (D) 8
πŸ’¬ Discuss
βœ… Correct Answer: (C) 7
Explanation: split(), ereg_replace(), ereg(), eregi(), eregi_replace(), sql_regcase(), and spliti() are the functions provided.

Q. What is the result of the following PHP code?

Code:
<?php
    $username = "Alex";
    if (preg_match("([^a-z])",$username))
        echo "Username must be all lowercase!";
    else
        echo "Username is all lowercase!";
?>
  • (A) Error
  • (B) Username must be all lowercase!
  • (C) Username is all lowercase!
  • (D) No Output
πŸ’¬ Discuss
βœ… Correct Answer: (B) Username must be all lowercase!
Explanation: The built-in function preg_match() returns whether a match was found in a string.

Q. POSIX stands for _________________?

  • (A) Portative Operating System Interface for Linux
  • (B) Portable Operating System Interface for Unix
  • (C) Portable Operating System Interface for Linux
  • (D) Portative Operating System Interface for Unix
πŸ’¬ Discuss
βœ… Correct Answer: (B) Portable Operating System Interface for Unix

Q. POSIX style regular expressions was deprecated in which version of PHP?

  • (A) PHP 4
  • (B) PHP 5
  • (C) PHP 5.2
  • (D) PHP 5.3
πŸ’¬ Discuss
βœ… Correct Answer: (D) PHP 5.3

Q. What is the result of the following PHP code?

Code:
<?php
    $names = array("alex", "jean", "emily", "jane");
    $name = preg_grep("/^e/", $names);
    print_r($name);
?>
  • (A) Array ( [0] => alex [1] => jean [2] => emily [3] => jane )
  • (B) Array ( [0] => alex )
  • (C) Array ( [2] => emily )
  • (D) Array ( [3] => jane )
πŸ’¬ Discuss
βœ… Correct Answer: (C) Array ( [2] => emily )
Explanation: The built-in function preg_grep() returns an array containing only items from the input that match the given pattern.

Q. What is the result of the following PHP code?

Code:
<?php
    $mail = "admin@example.com";
    $mail = str_replace("a","@",$mail);
    echo "Contact me at $mail.";
?>
  • (A) Contact me at @dmin@ex@mple.com.
  • (B) Contact me at admin@example.com.
  • (C) Contact me at adminaexample.com.
  • (D) Contact me at $mail.
πŸ’¬ Discuss
βœ… Correct Answer: (A) Contact me at @dmin@ex@mple.com.
Explanation: The built-in function The str_replace() replaces some characters with other characters in a string.

Q. Which PHP version provide Exception handling?

  • (A) PHP 6
  • (B) PHP 5.3
  • (C) PHP 5
  • (D) PHP 4
πŸ’¬ Discuss
βœ… Correct Answer: (C) PHP 5

Q. In PHP there are ____ error levels.

  • (A) 17
  • (B) 16
  • (C) 15
  • (D) 14
πŸ’¬ Discuss
βœ… Correct Answer: (B) 16