PHP String MCQs
PHP String MCQs : This section focuses on "String" in PHP. These Multiple Choice Questions (mcq) should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. In how many ways we can create strings in PHP?
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : B
Explanation: There are two ways of creating strings in PHP: single quote and double quote
2. Which type of string can processes special characters inside quotes?
A. single quote string
B. double quote string
C. Both A and B
D. None of the above
View Answer
Ans : B
Explanation: double-quote strings in PHP is capable of processing special characters.
3. Which of the following is not a Built-in String functions in php?
A. strlen()
B. str_replace()
C. strpos()
D. strreverse()
View Answer
Ans : D
Explanation: strreverse() function is not a Built-in String functions in php.
4. Why trim() function is used in php?
A. to remove whitespaces
B. to remove lowercase alphabet
C. to remove uppercase alphabet
D. to remove underscore
View Answer
Ans : A
Explanation: This trim() function allows us to remove whitespaces or strings from both sides of a string.
5. Which of the following is the output of the below code?
<?php
echo strpos("Hello letsfindcourse!", "lets"), " \n";
?>
A. 4
B. 5
C. 6
D. 7
View Answer
Ans : C
Explanation: 6 is the output of the following code.
6. Which of the following is the output of the below code?
<?php
var_dump(strpos("Hello letsfindcourse!", "course"));
?>
A. int(13)
B. char(14)
C. int(14)
D. int(15)
View Answer
Ans : C
Explanation: int(14) is the output of the following code.
7. Which is true about var_dump() function?
A. var_dump() loops infinitely
B. var_dump() cuts off loop afetr getting same element two times
C. var_dump() cuts off loop after getting the same element three times
D. var_dump() cuts off loop after getting the same element five times
View Answer
Ans : C
Explanation: var_dump() cuts off loop after getting the same element three times is true about var_dump() function.
8. The ________ function compares the two strings s1 and s2, ignoring the case of the characters.
A. strtolower()
B. toLowerCase()
C. strcasecmp()
D. lc()
View Answer
Ans : C
Explanation: The strcasecmp() function compares the two strings s1 and s2, ignoring the case of the characters.
9. Returns a string arguments with trilling blank space removed, is a behavior of
A. starts( ) function
B. chop( ) function
C. rtrim( ) function
D. lc()
View Answer
Ans : D
Explanation: Returns a string arguments with trilling blank space removed, is a behavior of chop ( ) function and rtrim ( ) function
10. What is the output of the following php code?
<?php
$username = "letsfindcourse";
if (preg_match("([^a-z])",$username))
echo "Name must be all lowercase!";
else
echo "Name is all lowercase!";
?>
A. Error
B. No Output
C. Name must be all lowercase!
D. Name is all lowercase!
View Answer
Ans : D
Explanation: The name is all lowercase! is the output of the following PHP code.
11. Predict the output of the following code snippet :
<?php
$str="chess was played";
echo strlen(substr($str,3,2))."
"
?>
A. 1
B. 2
C. 3
D. Array
View Answer
Ans : B
Explanation: 2 the output of the following code snippet.
12. Predict the output of the following code snippet :
<?php
echo count_chars("AA",1);
?>
A. 2
B. [65]=>2
C. Array
D. None of the above
View Answer
Ans : C
Explanation: Array will be the output of the following statement
13. A variable $str is set to "HELLO WORLD", which of the following script returns it title case?
A. echo ucwords($str)
B. echo ucwords(strtolower($str)
C. echo ucfirst($str)
D. echo ucfirst(strtolower($str)
View Answer
Ans : B
Explanation: echo ucwords(strtolower($str) script returns it title case.
14. The PHP function searches for a specific text within a string.
A. strpos()
B. strposition()
C. strrev()
D. str_replace()
View Answer
Ans : A
Explanation: The PHP strpos() function searches for a specific text within a string.
15. Which function is used to Calculate a 32-bit CRC for a string?
A. crc32()
B. crypt()
C. heb32()
D. heb32c()
View Answer
Ans : A
Explanation: crc32() function is used to Calculate a 32-bit CRC for a string.
16. What is the use of htmlentities() function in php?
A. Converts characters to HTML entities
B. Converts HTML entities to characters
C. Converts some predefined HTML entities to characters
D. Converts some predefined characters to HTML entities
View Answer
Ans : A
Explanation: The use of htmlentities() function in php is to Converts characters to HTML entities
17. How many functions does PHP offer for searching and modifying strings using Perl-compatible regular expressions.
A. 7
B. 8
C. 9
D. 10
View Answer
Ans : B
Explanation: The functions are preg_filter(), preg_grep(), preg_match(), preg_match_all(), preg_quote(), preg_replace(), preg_replace_callback(), and preg_split().
18. What will be the output of the following PHP code?
<?php
$title = "O malley wins the heavyweight championship!";
echo ucwords($title);
?>
A. O Malley Wins The Heavyweight Championship!
B. O malley Wins The Heavyweight Championship!
C. O Malley wins the heavyweight championship!
D. o malley wins the heavyweight championship!
View Answer
Ans : D
Explanation: The ucwords() function capitalizes the first letter of each word in a string. Its prototype follows:string ucwords(string str)
19. What will be the output of the following PHP code?
<?php
$url = "lfc123456@example.com";
echo ltrim(strstr($url, "@"),"@");
?>
A. lfc123456@example.com
B. lfc123456
C. lfc123456@
D. example.com
View Answer
Ans : D
Explanation: The strstr() function returns the remainder of a string beginning with the first occurrence of a predefined string.
20. How many functions does PHP offer for searching strings using POSIX style regular expression?
A. 7
B. 8
C. 9
D. 10
View Answer
Ans : A
Explanation: ereg(), ereg_replace(), eregi(), eregi_replace(), split(), spliti(), and sql_regcase() are the functions offered.
Also check :
Discussion