11+ Unlock Mastery PHP Strings MCQ Questions and Answers

PHP Strings MCQ Questions and Answers

Before looking 11+ Unlock Mastery PHP Strings MCQ Questions and Answers, first of all, we have to know What is a string in PHP. A string is a sequence of characters, which can be letters, numbers, or other special characters. Strings are used to store and manipulate text. In PHP, you can define strings using single quotes (‘) or double quotes (“).

Join to Become PHP Web Developer - Future Scope Career Guidance

WhatsApp Group Join Now
Telegram Group Join Now
Follow On Instagram Follow Us

How to Declare a String in PHP?


Following is the list of PHP Strings MCQ Questions and Answers

Which PHP function is used to determine the length of a string?

  1. strlen()
  2. str_length()
  3. string_length()
  4. count_chars()

Answer: 1. strlen()

What is string length?

String length is the counting of the number of characters in a string. We using strlen() function for counting length of a string.

For example, “quizlancer” is a string, so the answer if 10 is the length of a string, you thought why 10, because there are 10 characters in a “quizlancer” string.


Which function is used to convert a string to all lowercase letters in PHP?

  1. strtolower()
  2. lc_string()
  3. toLowerCase()
  4. makeLower()

Answer: 1. strtolower()


Which PHP function is used to find the position of the first occurrence of a substring in a string?

  1. strpos()
  2. findstr()
  3. substr_pos()
  4. str_search()

Answer: 1. strpos()


What function is used to extract a part of a string in PHP?

  1. substr()
  2. extract_str()
  3. slice()
  4. get_part()

Answer: 1. substr()


Top 5 PHP String Functions You Should Know as a Developer


Which PHP function is used to replace a part of a string with another string?

  1. str_replace()
  2. replace_str()
  3. switch_str()
  4. replace()

Answer: 1. str_replace()


What function is used to compare two strings in PHP, considering their similarity and returns the number of matching characters in the same position?

  1. compareStrings()
  2. str_cmp()
  3. similar_text()
  4. match_strings()

Answer: 3. similar_text()


Which function is used to trim whitespace or other characters from the start and end of a string in PHP?

  1. trim()
  2. clear()
  3. strip()
  4. clean()

Answer: 1. trim()


What is the function used to split a string into an array in PHP based on a specified delimiter?

  1. explode()
  2. split_str()
  3. separate()
  4. str_split()

Answer: 1) explode()


Which PHP function is used to reverse a string?

  1. str_reverse()
  2. reverse_str()
  3. strrev()
  4. flip_str()

Answer: 3. strrev()


What function is used to find the last occurrence of a character in a string in PHP?

  1. last_position()
  2. strripos()
  3. str_last()
  4. find_last()

Answer: 2. strripos()


Which PHP function is used to convert special characters to HTML entities?

  1. html_entities()
  2. special_chars()
  3. htmlentities()
  4. encode_special()

Answer: 3. htmlentities()


What function is used to check if a string contains another string in PHP?

  1. has_string()
  2. str_contains()
  3. string_exists()
  4. contains_str()

Answer: 2. str_contains()


Which PHP function is used to pad a string to a certain length with another string?

  1. string_pad()
  2. pad_str()
  3. str_pad()
  4. fill_str()

Answer: 3. str_pad()


What function is used to convert a string to an array in PHP?

  1. string_to_array()
  2. str_array()
  3. string_split()
  4. str_split()

Answer: 4. str_split()


Which PHP function is used to find the difference between two strings?

  1. str_diff()
  2. difference()
  3. str_compare()
  4. levenshtein()

Answer: 4. levenshtein()


What function is used to count the number of occurrences of a substring in a string in PHP?

  1. str_count()
  2. count_substring()
  3. substr_count()
  4. sub_count()

Answer: 3. substr_count()


Which PHP function is used to convert a string representation of variables into variables?

  1. var_convert()
  2. string_to_vars()
  3. str_to_var()
  4. parse_str()

Answer: 4. parse_str()


What function is used to convert a PHP array to a string?

  1. array_to_str()
  2. stringify_array()
  3. implode()
  4. join_str()

Answer: 3. implode()


Which PHP function is used to capitalize the first character of a string?

  1. capitalize()
  2. first_capital()
  3. uc_first()
  4. ucfirst()

Answer: 4. ucfirst()


What function is used to remove HTML and PHP tags from a string in PHP?

  1. strip_tags()
  2. remove_tags()
  3. clean_tags()
  4. delete_tags()

Answer: 1. strip_tags()


How do I concatenate strings in PHP?

  1. $string1 + $string2
  2. $string1 . $string2
  3. $string1 : $string2
  4. $string1 & $string2

Answer: 2. $string1 . $string2


What function do you use to compare two strings in PHP

Answer: 1. strcmp()


What will be the output of the following PHP code?

  1. Hello World
  2. HELLO WORLD
  3. hello world
  4. hello world

Answer: 2. HELLO WORLD


Quiz on PHP Strings MCQ Questions and Answers

0%
7
Created on By quizlancer

PHP String Functions

1 / 10

1. Which function is used to remove whitespace or other predefined characters from the right side of a string?

2 / 10

2. Which function is used for reversing a string?

3 / 10

3. The ______ function converts a string to lowercase.

4 / 10

4. When two strings are exactly equivalent Strcmp ( ) returns what?

5 / 10

5. Which function is used for repeating a string a specified number of times?

6 / 10

6. Which functions return the length of the string?

7 / 10

7. ______ function counts the number of words in a string.

8 / 10

8. Which function is used to convert all characters to uppercase?

9 / 10

9. Which is a function that compares two strings.

10 / 10

10. Which function is used to concatenate two strings in PHP?

Your score is

The average score is 61%

0%


Follow Us on Telegram

Follow Quiz Lancer Telegram Channel to solve daily interview questions. We share important interview questions which are asked in the interview. Most of the students get good values from this channel and got selected as a developer.


FAQ on PHP Strings MCQ Questions and Answers

  1. What is the difference between single-quoted and double-quoted strings in PHP?

    Single-quoted strings are more literal and do not parse variables or interpret escape sequences, except for escaping single quotes with a backslash (\'). Double-quoted strings allow variable interpolation and interpret escape sequences, making them more flexible.
    Let me explain you by example.
    $name = "PHP";
    echo 'Hello, $name!'; // Output: Hello, $name!
    echo "Hello, $name!"; // Output: Hello, PHP!

  2. How can I find the length of a string in PHP?

    We can use the strlen() function to get the length of a string in PHP. For example:
    $text = “Hello, PHP”;
    $length = strlen($text); // Result: 10

  3. How to get string type in PHP?

    The is_string() function checks whether a variable is of type string or not. This function returns true (1) if the variable is of type string, otherwise it returns false/nothing.


80 / 100
Scroll to Top