PHP Questions and Answers – Regular Expressions
This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Regular Expressions”.
1. Both POSIX regex and PERL regex are example of ___________
A Delimitering
B Tokenizing
C Regular expressions
D None of them
2. Which of the following function is not listed in PHP6?
A ereg()
B eregi()
C ereg_replace()
D All of them
3. Which of the following regular expression matches any string containing 0 or 1 P?
A p*
B p#
C p+
D P?
4. [:hello:] can also be specified as ____________
A [a-z]
B [A-z]
C [A-za-z]
D [A-Za-z0-9] .
5. How many functions does PHP provide for searching strings using POSIX style regular expression?
A 5
B 6
C 7
D 8
6. What is the result of the following PHP 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
7. 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
8. 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
9. What is the result of the following PHP 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 )
10. What is the result of the following PHP code?
<?php $mail = "[email protected]"; $mail = str_replace("a","@",$mail); echo "Contact me at $mail."; ?>
A Contact me at @dmin@[email protected].
B Contact me at [email protected].
C Contact me at adminaexample.com.
D Contact me at $mail.