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 (“).
How to Declare a String in PHP?
$singleQuotedString = 'This is a single-quoted string.';
$doubleQuotedString = "This is a double-quoted string.";
Following is the list of PHP Strings MCQ Questions and Answers
Which PHP function is used to determine the length of a string?
- strlen()
- str_length()
- string_length()
- 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?
- strtolower()
- lc_string()
- toLowerCase()
- makeLower()
Answer: 1. strtolower()
Which PHP function is used to find the position of the first occurrence of a substring in a string?
- strpos()
- findstr()
- substr_pos()
- str_search()
Answer: 1. strpos()
What function is used to extract a part of a string in PHP?
- substr()
- extract_str()
- slice()
- 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?
- str_replace()
- replace_str()
- switch_str()
- 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?
- compareStrings()
- str_cmp()
- similar_text()
- 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?
- trim()
- clear()
- strip()
- clean()
Answer: 1. trim()
What is the function used to split a string into an array in PHP based on a specified delimiter?
- explode()
- split_str()
- separate()
- str_split()
Answer: 1) explode()
Which PHP function is used to reverse a string?
- str_reverse()
- reverse_str()
- strrev()
- flip_str()
Answer: 3. strrev()
What function is used to find the last occurrence of a character in a string in PHP?
- last_position()
- strripos()
- str_last()
- find_last()
Answer: 2. strripos()
Which PHP function is used to convert special characters to HTML entities?
- html_entities()
- special_chars()
- htmlentities()
- encode_special()
Answer: 3. htmlentities()
What function is used to check if a string contains another string in PHP?
- has_string()
- str_contains()
- string_exists()
- contains_str()
Answer: 2. str_contains()
Which PHP function is used to pad a string to a certain length with another string?
- string_pad()
- pad_str()
- str_pad()
- fill_str()
Answer: 3. str_pad()
What function is used to convert a string to an array in PHP?
- string_to_array()
- str_array()
- string_split()
- str_split()
Answer: 4. str_split()
Which PHP function is used to find the difference between two strings?
- str_diff()
- difference()
- str_compare()
- levenshtein()
Answer: 4. levenshtein()
What function is used to count the number of occurrences of a substring in a string in PHP?
- str_count()
- count_substring()
- substr_count()
- sub_count()
Answer: 3. substr_count()
Which PHP function is used to convert a string representation of variables into variables?
- var_convert()
- string_to_vars()
- str_to_var()
- parse_str()
Answer: 4. parse_str()
What function is used to convert a PHP array to a string?
- array_to_str()
- stringify_array()
- implode()
- join_str()
Answer: 3. implode()
Which PHP function is used to capitalize the first character of a string?
- capitalize()
- first_capital()
- uc_first()
- ucfirst()
Answer: 4. ucfirst()
What function is used to remove HTML and PHP tags from a string in PHP?
- strip_tags()
- remove_tags()
- clean_tags()
- delete_tags()
Answer: 1. strip_tags()
How do I concatenate strings in PHP?
- $string1 + $string2
- $string1 . $string2
- $string1 : $string2
- $string1 & $string2
Answer: 2. $string1 . $string2
Answer: 1. strcmp()
What will be the output of the following PHP code?
echo strtoupper("hello world");
- Hello World
- HELLO WORLD
- hello world
- hello world
Answer: 2. HELLO WORLD
Quiz on PHP Strings MCQ Questions and Answers
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
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!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: 10How 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.