PHP String MCQs
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.
Discussion