Home > PHP & Programming > Quizzes > PHP Programming Basics Practice Test: Strings And Regular Expression in PHP
PHP Programming Basics Practice Test: Strings And Regular Expression in PHP
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 0% Most missed: “What will be the output of the following PHP code?”
In PHP, regular expressions are strings that contain delimiters, a pattern, and optional modifiers. For example, /fatskills/i is a regular expression that contains the delimiter /, the pattern fatskills, and the modifier i, which makes the search case-insensitive.   Here are some things to keep in mind about regular expressions in PHP: The delimiter can be any character that is not a letter, number, backslash, or space. The forward slash (/) is the most common delimiter, but you can use other delimiters like # or ~ when your pattern contains forward slashes. The expression is contained... Show more
PHP Programming Basics Practice Test: Strings And Regular Expression in PHP
Time left 00:00
18 Questions

1. Which one of the following functions can be used to concatenate array elements to form a single delimited string?
2. Say we have two compare two strings which of the following function/functions can you use?
i) strcmp()
ii) strcasecmp()
iii) strspn()
iv) strcspn()
3. POSIX implementation was deprecated in which version of PHP?
4. How many functions does PHP offer for searching strings using POSIX style regular expression?
5. What will be the output of the following PHP code?
echo str_pad("Salad", 5)." is good.";
?>
6. Which among the following is/are not a metacharacter?
i) \a
ii) \A
iii) \b
iv) \B
7. PHP has long supported two regular expression implementations known as _______ and _______
i) Perl
ii) PEAR
iii) Pearl
iv) POSIX
8. Which one of the following functions finds the last occurrence of a string, returning its numerical position?
9. What will be the output of the following PHP code?
$title = "O'malley wins the heavyweight championship!";
echo ucwords($title);
?>
10. What will be the output of the following PHP code?
$text = "this is\tsome text that\nwe might like to parse.";
print_r(split("[\n\t]",$text));
?>
11. POSIX stands for ____________
12. What will be the output of the following PHP code?
$foods = array("pasta", "steak", "fish", "potatoes");
$food = preg_grep("/^s/", $foods);
print_r($food);
?>
13. What will be the output of the following PHP code?
$username = "jasoN";
if (ereg("([^a-z])",$username))
echo "Username must be all lowercase!";
else
echo "Username is all lowercase!";
?>
14. Which of the following would be a potential match for the Perl-based regular expression /fo{2,4}/?
i) fol
ii) fool
iii) fooool
iv) fooooool
15. Which one of the following regular expression matches any string containing zero or one p?
16. Which one of the following functions will convert a string to all uppercase?
17. [:alpha:] can also be specified as ________
18. How many functions does PHP offer for searching and modifying strings using Perl-compatible regular expressions.