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


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


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


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


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


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


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


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


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


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


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


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


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


14. The PHP function searches for a specific text within a string.

A. strpos()
B. strposition()
C. strrev()
D. str_replace()

View Answer


15. Which function is used to Calculate a 32-bit CRC for a string?

A. crc32()
B. crypt()
C. heb32()
D. heb32c()

View Answer


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


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


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


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


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





Also check :


Discussion



* You must be logged in to add comment.