MCQ

PHP Questions and Answers – String – Part 2

This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “String”.
 

1. Which function is used for replacing the entire string with an alternative string?

A Replace()

B Str_replace()

C Strrpos()

D Strstr()

B
Str_replace() is used for replacing the entire string with an alternative string. Example:

<?php 
    echo str_replace("Alex", "World", "Hello Alex!");  
    //Output: Hello World!
?>

 

 

2. Stristr() is same to Strstr() except that ______

A The comparison is case independent

B The comparison start from middle

C The comparison is case sensitive

D None of them

A
The comparison is case independent.

 

 

3. Which one of the following function is used to capitalize first letter of each word in a string?

A strtupper()

B strword()

C ucwords()

D ucfirst()

C
The comparison is case independent. Example:

<?php 
    echo ucwords("hello world");
    //Output: Hello World
?>

 

 

4. Strstr() function allow us to select a substring by its ______

A Position

B Numerical value

C Content

D None of them

C
The built-in function Strstr() allow us to select a substring by its content. Example:

<?php 
    echo strstr("Hello world!","wor");
?>

Output:

world!

 

 

5. Which one of the following function is used to remove blank space in a String?

A chop()

B rtrim()

C starts()

D Both A and B

D
Both chop() and trim() are used to remove blank space in a String.

 

 

6. If you want to check if a string is equal to another string which function you can use?

A strpos()

B str()

C strpid()

D All of them

A
The built-in function strpos() is used to check if a string is equal to another string. Example:

if (strpos($str, $needle) === 0)
{
    // the $needle is found at position 0 in the $str
}

 

 

7. What is the opposite function of explode()?

A str()

B impose()

C strtok()

D implode()

D
implode() function is used to concatenate array elements to a single string. Example:

<?php 
    $arr = array('Welcome','to','StackHowTo!');
    echo implode(" ",$arr);
?>

Output:

Welcome to StackHowTo!

 

 

8. MD5 is not secure to store passwords because It__________

A generates output in hexadecimal values

B generates the same output string as given input string

C generates Boolean results

D None of them

B
MD5 is not secure to store passwords because It generates the same output string as given input string.

 

 

9. A function that receives a filename as argument and returns a MD5 of that file

A md_file()

B md5()

C md5_file()

D digest_file()

C
md5_file() receives a filename as argument and returns a MD5 of that file.

 

 

10. Which one of the following function is used to receive a string as argument and returns a string that is stripped of all HTML and PHP tags?

A nl2br()

B strip()

C strip_tags()

D All of them

C
The built-in function strip_tags() is used to receive a string as argument and returns a string that is stripped of all HTML and PHP tags. Example:

<?php 
    echo strip_tags("Hello <b>world!</b>");
?>

Output

Hello world!

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *